All fragments on backstack, have nulls in onSaveInstanceState, after rotation
After rotating a device, any fragment we have on the backstack or in the fragmentSupportManager, activates the onSaveInstanceState.
However, after the first rotation, everything inside is null (all variables) and the app crashes with null pointer exceptions.
I'm wondering why if the fragment is virtually destroyed to nothing (all values are null) why the fragment still exists and onSaveInstanceState is being called?
My code is quite deep, with multiple base classes, and presenter classes to lift a lot of the code out of the fragments. I'm also only using one Activity and using fragmentTransaction.replace.
I can add code if people require it, but there's a lot! I'm hoping there is something obvious or something that I don't understand about the way the backstack works/retains it's fragments.
links I have looked at that haven't helped are
Will onSaveInstanceState be called on fragments in the back stack?
Once for all, how to correctly save instance state of Fragments in back stack?
Using onSaveInstanceState with fragments in backstack?
BackStack Fragments blank on rotation
Save state of fragments in backstack
I have exactly the same problem. Lets say I have Frag A, calling Frag B When I get from Frag A to Frag B, Frag A exists on backstack and is not showing. While in Frag B, on a first rotate the onSavedInstanceState()
is being called for Frag A and it works fine, since the Frag A on back stack exists and all the data was there.. When I rotate the device again in Frag B, the Frag A onSavedInstanceState()
is called again for some unknown reason.. between these calls a restore was never issued since onCreateView has not been called since Frag A is not visible. Why it is doing that I have 0 clue.
What I do, is I check if Bundle is empty (and bundle does exist after 2nd rotate, its just empty) and if it is, I try to recreate Frag from scratch, which means reloading fresh data from a request... which is not the best solution..
链接地址: http://www.djcxy.com/p/58706.html上一篇: c ++模板似乎打破了访问说明符