android - onSaveInstanceState Not writing data -


my application has 2 activity's. need activity save string, used method below.

@override protected void onsaveinstancestate(bundle bundle) {   bundle.putstring("activity", "dados que precisando ser salvos!");   super.onsaveinstancestate(bundle); } 

when go second activity above method called, correct behavior in application. upon returning first activity, bundle null, , i'm not understanding why, can me?

@override protected void oncreate(bundle savedinstancestate) {    super.oncreate(savedinstancestate);    if (savedinstancestate != null){    string teste = savedinstancestate.getstring("activity");    } } 

override

onrestoreinstancestate() want values extracted :

@override  public void onrestoreinstancestate(bundle savedinstancestate) {   super.onrestoreinstancestate(savedinstancestate);   // restore ui state savedinstancestate.    // bundle has been passed oncreate.    string mystring = savedinstancestate.getstring("activity"); } 

best practice use both method in same activity restore , use data other activity, can use shared preference or pass intent.


Comments

Popular posts from this blog

Sort a complex associative array in PHP -

vb.net - How to ignore if a cell is empty nothing -

recursion - Can every recursive algorithm be improved with dynamic programming? -