Search code examples
androidandroid-architecture-componentsandroid-architecture-lifecycle

Android Architecture Components Lifecycle state


https://developer.android.com/reference/android/arch/lifecycle/Lifecycle.State.html

STARTED Lifecycle.State STARTED For an Activity, this state is reached in two cases: after onStart call; right before onPause call.

As the above documentation says, I couldn't understand the rationale behind the STARTED state right before onPause call. Can someone please explain that?


Solution

  • Notice that the values in the Lifecycle.State enum do not include a PAUSED state. There are only five states: CREATED, DESTROYED, INITIALIZED, RESUMED, STARTED. These do not exactly correspond with the normal Activity lifecycle that we all know and love:

    Lifecycle states

    Also note the following from the Lifecycle class documentation:

    ON_CREATE, ON_START, ON_RESUME events in this class are dispatched after the LifecycleOwner's related method returns. ON_PAUSE, ON_STOP, ON_DESTROY events in this class are dispatched before the LifecycleOwner's related method is called

    The execution of the onPause() is the closing boundary for the RESUMED state. At this point, the Activity is no longer considered RESUMED and it is certainly not DESTROYED. Since we don't have a PAUSED state it follows it must now be in the STARTED state. This is technically true, the Activity hasn't yet stopped but it is no longer resumed.