When to remove fragments displaying un-retained state?
Fragments are recreated automatically when their parent Activity or Fragment is recreated. If the child fragments were related to state that is not retained between instances of their parent, when should I remove them? In the parent fragment's onDestroy(): unreliable since onDestroy() might not be called. In the parent fragment's onCreate(): presumably the children have not yet been created at this point. Some other lifecycle method that is guaranteed to be called after the children have been recreated and added. Is onViewStateRestored(...) the right place for this? In case my question isn't clear, here's an example: An Activity has a Fragment which contains an asynchronous operation. The fragment would normally cancel this task in onDestroy(). But if the fragment is destroyed without onDestroy() being called, it may later find itself recreated with the background task uninitialized. In that case, it should remove its old progress dialog. When should it test for this condition? Edit: When the user swipes the app out of recents, all its components are destroyed without calls to onDestroy(). But in that case, the fragment hierarchy is apparently obliterated along with the rest of the app. When the app is restarted, the fragment is not automatically recreated, so I don't have to worry about removing it. When the fragment is destroyed because its host activity is put in the background and "don't keep activities" is turned on, the fragment is automatically recreated. But in that case, it seems I can count on onDestroy() being called. My concern is what happens when the app is killed to free memory. Hopefully it will behave like swiping from recents, where the fragment hierarchy is not restored. That would render my whole question moot. Can anyone confirm what happens in that case?
The docs seem to indicate onpause will always be called https://developer.android.com/guide/components/fragments.html or if you know the activity is going to be destroyed onDetach() must be called since if the activity is destroyed the fragment can't be attached.
Android - PendingIntent.FLAG_CANCEL_CURRENT - does it really cancel alarmManager previous pending intent?
How to refresh listview from another fagment tab
Receive an read SMS with correct encoding and convert to UTF8
I am facing following rendering problems in Android Studio when I try to open my project. How can I resolve it?
Generate Protobuf java files with Square's Wire
can not play mp3 file from raw folder in android
Showing the keyboard when my Editbox, contained in a Dialog, is focused
Espresso Tests stuck when run on multiple devices
Change the text of a “TextView” from onListItemClick
Webservice not receiving multipart PUT from android
The project was not built since its build path is incomplete. Cannot find the class file for android.content
How do I make a puzzle app in droid without running out of memory?
ADB connection via USB reverse tethered phone
How to fix table creation error in android sdk?
How to gitignore .idea/libraries and still keep a history of dependency versions?
Notification blocks UI