Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 274
Ashesh Bharadwaj Avatar asked Dec 04 '22 22:12

Ashesh Bharadwaj


1 Answers

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.

like image 135
David Rawson Avatar answered Dec 28 '22 05:12

David Rawson