android


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.

Related Links

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

Categories

HOME
xml
scikit-learn
apache-flink
ecmascript-6
sublimetext
rendering
google-cloud-functions
cublas
carousel
vxml
python-multithreading
data-visualization
crystal-reports-2013
minecraft-forge
reactive-programming
emoji
spring-social
supervisor
pybossa
eip
coin3d
linear-algebra
mvc-mini-profiler
html5-appcache
solrcloud
lilypond
drive
guzzle
string-concatenation
froala
motion-detection
genexus-sd
wcag
comparable
google-earth
event-flow
utorrent
erb
spring-security4
login-script
installscript
google-earth-engine
nohup
jide
pom.xml
double-click
getchar
httrack
textsum
magento-2.0.7
corruption
context-switch
cup
css-transforms
rackspace-cloud
gameplay-kit
bootstrap-tags-input
pocketsphinx-android
pure-css
custom-lists
myspace
dimension
vorpal.js
hadoop-partitioning
ascii-art
atan2
concurrentmodification
linklabel
grgit
avisynth
eoferror
zscript
vacuum
document-repository
dbaccess
addressing-mode
administration
deform
grails-domain-class
reflector
ios8-extension
authlogic
git-repo
code-duplication
dtmf
kaleidoscope
epiceditor
css-reset
traceability
sqlclr
web-notifications
fragmenttransaction
correlated-subquery
inkcanvas
user-tracking
jqote
uipagecontrol
dataform
mtu
message-passing
strtod
localizable.strings
great-circle

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile