I am really confused with the internal state of a Fragment.
I have an Activity holding only one Fragment at once and replaces it, if another Fragment should get shown. From the docs onSaveInstanceState
is called ONLY if the Activitys onSaveInstanceState
is getting called (which isn't called in my case).
If I stop my Fragment, I'll store its state myself inside a Singleton (yeah, I know I hate Singletons, too, but wasn't my idea to do so).
So I have to recreate the whole ViewHirarchy
, create new Views (by using the keyword new
), restore its state and return them in onCreateView
.
I also have a Checkbox inside this View from which I explicitly do NOT want to store its state.
However the FragmentManager
wants to be "intelligent" and calls onViewStateRestored
with a Bundle I never created myself, and "restores" the state of the old CheckBox
and applies it to my NEW CheckBox. This throws up so many questions:
Can I control the bundle from onViewStateRestored
?
How does the FragmentManager take the state of a (probably garbage-collected) CheckBox and applies it to the new one?
Why does it only save the state of the Checkbox (Not of TextViews??)
So to sum it up: How does onViewStateRestored
work?
Note I'm using Fragmentv4, so no API > 17 required for onViewStateRestored