Lifecycle | API reference | Android Developers (original) (raw)
public abstract class Lifecycle
Defines an object that has an Android Lifecycle. androidx.fragment.app.Fragment and androidx.fragment.app.FragmentActivity classes implement [LifecycleOwner](/reference/androidx/lifecycle/LifecycleOwner) interface which has the [ getLifecycle](/reference/androidx/lifecycle/LifecycleOwner#lifecycle%28%29) method to access the Lifecycle. You can also implement [LifecycleOwner](/reference/androidx/lifecycle/LifecycleOwner) in your own classes.
[Event.ON_CREATE](/reference/androidx/lifecycle/Lifecycle.Event#ON%5FCREATE), [Event.ON_START](/reference/androidx/lifecycle/Lifecycle.Event#ON%5FSTART), [Event.ON_RESUME](/reference/androidx/lifecycle/Lifecycle.Event#ON%5FRESUME) events in this class are dispatched after the [LifecycleOwner](/reference/androidx/lifecycle/LifecycleOwner)'s related method returns. [Event.ON_PAUSE](/reference/androidx/lifecycle/Lifecycle.Event#ON%5FPAUSE), [Event.ON_STOP](/reference/androidx/lifecycle/Lifecycle.Event#ON%5FSTOP), [Event.ON_DESTROY](/reference/androidx/lifecycle/Lifecycle.Event#ON%5FDESTROY) events in this class are dispatched before the [LifecycleOwner](/reference/androidx/lifecycle/LifecycleOwner)'s related method is called. For instance, [Event.ON_START](/reference/androidx/lifecycle/Lifecycle.Event#ON%5FSTART) will be dispatched after android.app.Activity.onStart returns, [Event.ON_STOP](/reference/androidx/lifecycle/Lifecycle.Event#ON%5FSTOP) will be dispatched before android.app.Activity.onStop is called. This gives you certain guarantees on which state the owner is in.
To observe lifecycle events call .addObserver passing an object that implements either [DefaultLifecycleObserver](/reference/androidx/lifecycle/DefaultLifecycleObserver) or [LifecycleEventObserver](/reference/androidx/lifecycle/LifecycleEventObserver).
Summary
Public constructors
Public methods
removeObserver
@MainThread
public abstract void removeObserver(@NonNull LifecycleObserver observer)
Removes the given observer from the observers list.
If this method is called while a state change is being dispatched,
- If the given observer has not yet received that event, it will not receive it.
- If the given observer has more than 1 method that observes the currently dispatched event and at least one of them received the event, all of them will receive the event and the removal will happen afterwards.