instance - Android Fragment and reload application -


i have fragmentactivity :

public class fragmentactivity extends fragmentactivity {     // ...     protected void oncreate(bundle savedinstancestate) {          if (savedinstancestate != null) {              myfragment = (myfragment) getsupportfragmentmanager().getfragment(             savedinstancestate, myfragment.class.getname());          }          else {              myfragment = new fragment(myobject);          }     } } 

and in fragment :

public class myfragment extends fragment {     public myfragment(myobject) {         super();         this.myobject = myobject;         setretaininstance(true);     }      @override     public view oncreateview(layoutinflater inflater, viewgroup container,             bundle savedinstancestate) {         mydao mydao = new mydao (myobject);     } } 

everything working except when close application, stuff (my application enters in background) , relaunch application. nullpointerexception on

mydao mydao = new mydao (myobject); 

where myobject null.

the savedinstancestate called ... don't understand how working.

ty

the system killing process , instance of myobject being garbage collected. setting instance retained helpful between orientation changes, keep in mind app running in background may killed when system runs out of memory. pass variable argument instead. it's important implement parcelable or serializable on mydao class.

ps.: need have empty constructor fragment because system recreates instance when activity recreated:

public myfragment() {  }   public myfragment(myobject) {     super();     setretaininstance(true);     bundle args = new bundle();     args.putparcelable("myobject", myobject);     setarguments(args); }   @override public view oncreateview(layoutinflater inflater, viewgroup container,         bundle savedinstancestate) {     myobject = getarguments().getparcelable("myobject");     mydao mydao = new mydao (myobject); } 

Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -