Is onDestroy() guaranteed to be called for Fragments?

android, android-fragments

Solution

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

Problem

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.

Original source

Related problems