Hope somebody can help me to understand this:
I am using a single-activity app and lots of Fragments that are replaced in the same container, and I am testing my app in a real device with the "Don't keep activities" option enabled
When a new fragment is added (using
FragmentTransaction replace()
method), I am using thesetArguments()
method to pass information to the new Fragment. It works as expected and I can get that information withgetArguments()
inside that Fragment. Everything ok so far ...After this, I send my app to background. I see that all the fragments in the stack are being destroyed, again as expected
I bring my app to foreground and in the
getArguments()
method I am getting an emptyBundle
(not null, just an empty Object) instead of the one with the data I used in #2
According to Android documentation, the arguments supplied in setArguments()
will be retained across fragment destroy and creation ... So, my questions are:
Does the "will be retained across fragment destroy and creation" includes the scenario I described?
Does the "Don't keep activities" option can mess up with
getArguments()
/setArguments()
if it is enabled?Is there a way to test proper fragment creation/destroy besides the "Don't keep activities" option?
What is the better approach to properly keep fragment's arguments "alive"? I could save them in the onSaveInstanceState() method, but would like to know if there are more options besides that.