Saturday 15 September 2012

android - savedInstanceState is null in onCreateView for Fragment when return from another activity not when return from other apps -



android - savedInstanceState is null in onCreateView for Fragment when return from another activity not when return from other apps -

update

the workaround able find create static variable , store state in there. not solution, works.

i tried saving state in activity activity's onrestoreinstancestate never called.

i not using setretaininstance().

when on fragment , rotate device or multi-task app , come back, savedinstancestate not null in oncreateview. but when remain in app , click item in fragment's listview , utilize intent show different activity , nail button homecoming original activity (which shows fragment), is null! why?

note: reply in how can maintain fragment state when added stack? did not work. instance variables in default states when homecoming other activity.

//it android.support.v4.app.fragment; @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { //only shows null when returning activity in app log.v(getclass().getsimplename(), "null?" + savedinstancestate); homecoming createmyview(); } @override public void onsaveinstancestate(bundle outstate) { //save value (it not null here) outstate.putint("testkey", "saved_key" ); //save state super.onsaveinstancestate(outstate); //this never null, should ok log.v(getclass().getsimplename(), "outstate : " + outstate); } @override public void onviewstaterestored(bundle savedinstancestate) { //savedinstancestate null here (when returning within same app)! super.onviewstaterestored(savedinstancestate); }

why null when returning activity not when returning other apps?

android android-fragments

No comments:

Post a Comment