Related Question.
I put together a simple app that goes like this:
Activity -> FirstFragment
Activity: onCreate() -> createFirstFragment()
FirstFragment firstFragment = (FirstFragment) getSupportFragmentManager().findFragmentByTag(FirstFragment.TAG);
if (firstFragment == null)
{
firstFragment = FirstFragment.newInstance();
getSupportFragmentManager()
.beginTransaction()
.add(R.id.firstFragmentContainer, firstFragment, FirstFragment.TAG)
.hide(firstFragment)
//.addToBackStack(null)
.commit();
}
Plain and simple, during onCreate()
add and hide a fragment so that I can do show/hide animations later.
Now, my question is this: why does the Activity
/FragmentManager
not remember this transaction (regardless of whether I .addToBackStack()
or setRetainInstance(true)
on the fragment) when the activity is killed and recreated? You can test this by checking the Do not keep activities
developer option. Start the app, firstFragment
is hidden as expected, minimize and come back, and viola! firstFragment
is there for all the world to see!
I would expect that this sort of thing would be managed by Android, or do I need to specifically record all my transactions and repeat them when the app is recreated?
Any help/advice would be greatly appreciated!
Edit: Also see related logged bug