java - Why my android app is crashing periodically? -


my application crashes whenever location changed. application structure simple: there 1 activity , many fragments. conclusion fragment carried out follows:

itemsfragment itemsfragment = new itemsfragment () {groupid = groupid, currentgroup = currentgroup}; itemsfragment.retaininstance = true; var fragmentmanager = supportfragmentmanager.begintransaction (); fragmentmanager.replace (resource.id.flcontent, (supportfragment) itemsfragment); fragmentmanager.addtobackstack (null); fragmentmanager.commit (); 

i use c # xamarin, java principle same, different syntax. newbie android-developers understand reason.

on mobile device produces error:

“unfortunately app has stopped” 

where can put try... catch , got error:

java.lang.illegalstateexception: can not perform action after onsaveinstancestate 

the reason replacing fragments after activity has paused. easiest way fix use fragmentmanager.commitallowingstateloss();

as @user13 mentioned, easiest, , worst way.
if want solution, should check if activity state ok replace fragment before replacing it


Comments