Lifecycle

public abstract class Lifecycle
extends Object

java.lang.Object
   ↳ androidx.lifecycle.Lifecycle


Defines an object that has an Android Lifecycle. Fragment and FragmentActivity classes implement LifecycleOwner interface which has the getLifecycle method to access the Lifecycle. You can also implement LifecycleOwner in your own classes.

Lifecycle.Event.ON_CREATE, Lifecycle.Event.ON_START, Lifecycle.Event.ON_RESUME events in this class are dispatched after the LifecycleOwner's related method returns. Lifecycle.Event.ON_PAUSE, Lifecycle.Event.ON_STOP, Lifecycle.Event.ON_DESTROY events in this class are dispatched before the LifecycleOwner's related method is called. For instance, Lifecycle.Event.ON_START will be dispatched after onStart returns, Lifecycle.Event.ON_STOP will be dispatched before onStop is called. This gives you certain guarantees on which state the owner is in.

To observe lifecycle events call addObserver(LifecycleObserver) passing an object that implements either DefaultLifecycleObserver or LifecycleEventObserver.

Summary

Nested classes

enum Lifecycle.Event

 

enum Lifecycle.State

Lifecycle states. 

Public constructors

Lifecycle()

Public methods

abstract void addObserver(LifecycleObserver observer)

Adds a LifecycleObserver that will be notified when the LifecycleOwner changes state.

abstract Lifecycle.State getCurrentState()

Returns the current state of the Lifecycle.

abstract void removeObserver(LifecycleObserver observer)

Removes the given observer from the observers list.

Inherited methods