I know for an Activity onDestroy(...)
is not guaranteed to be called. According to the docs,
There are situations where the system will simply kill the activity's hosting process without >calling this method (or any others) in it, so it should not be used to do things that are >intended to remain around after the process goes away.
Does this also apply to Fragments? Nothing is stated in the docs but just want to make sure.
Android Activity onDestroy() is not always called and if called only part of the code is executed. Save this question. Show activity on this post. onDestroy() is not always called.
If onDestroy() is called as the result of a configuration change, the system immediately creates a new activity instance and then calls onCreate( ) on that new instance in the new configuration.
onDestroy() is a method called by the framework when your activity is closing down. It is called to allow your activity to do any shut-down operations it may wish to do.
Fragment and View STARTED When the fragment becomes STARTED , the onStart() callback is invoked.
I believe that Fragment's onDestroy()
is not guaranteed to be called just as Activity's.
In Activity's performDestroy()
:
final void performDestroy() {
mDestroyed = true;
mWindow.destroy();
mFragments.dispatchDestroy();
onDestroy();
if (mLoaderManager != null) {
mLoaderManager.doDestroy();
}
}
where mFragments.dispatchDestroy()
will finally call fragments onDestroy()
, if you digg into the source. So, if Activity's onDestroy()
not called, fragment's onDestroy()
won't be called.
And there's some other links:
fragment lifecycle: when "ondestroy" and "ondestroyview" are not called?
Android fragments lifecycle onStop, onDestroyView, onDestroy and onDetach
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With