Scenario:
- An Android app has an
Activity
with aFragment
. - The user sends the app to the background by pressing the home key.
- Two hours pass, the Android OS kills the process to free up resources.
- The user switches back to the app through the Recent Apps List.
The onCreate
method of the Activity will now find the existing Fragment by using fragmentManager.findFragmentByTag()
* as best practice cites. Yet, adding this old fragment to the activity will not make the fragment render. I'm unsure if I'm doing something wrong, or this is simply not a supported use case for reusing old fragments.
Must I implement special handling of this scenario (i.e. new
up the Fragment instead of reusing the old)? If so, what is the best practice of detecting that the process has been killed and relaunched in onCreate
?
edit 1: *) I am testing this by using DDMS to kill the process. This might not emulate the OS' way terminating a process correctly, as for instance onDestroy()
is not called. Does anoyone know if the old fragments are disposed from the FragmentManager when onDestroy()
is invoked by the OS? If this is the case, this question is moot.