In an Android app-
Say I am in an Activity
- MyActivity which holds one Fragment
at a time.
First I loaded Fragment A to it (With no tags I added it to back stack of the FragmentManager
)
Then at some point I loaded Fragment B (Again with no tags I added it to back stack of the FragmentManager
)
Then at some point i loaded Fragment C (Again with no tags I added it to back stack of the FragmentManager
)
I am using popBackStack()
to enable back button behavior so whenever I press back from Fragment C the flow is like:
Fragment C -> Fragment B -> Fragment A -> Close MyActivity..
Everything is perfect :-)
But if I am in Fragment C and the app gets killed in background (I used "do not keep activity flag" from Settings)
and come back online Fragment C is loaded in MyActivity
but the FragmentManager
's back stack contains only Fragment C..
The Back button is messing it up
Fragment C -> Close MyActivity..
Why is it so?
How to properly restore FragmentManager
's back stack within an Activity
?