public abstract class Lifecycle

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

Event.ON_CREATE, Event.ON_START, Event.ON_RESUME events in this class are dispatched after the LifecycleOwner's related method returns. Event.ON_PAUSE, Event.ON_STOP, Event.ON_DESTROY events in this class are dispatched before the LifecycleOwner's related method is called. For instance, Event.ON_START will be dispatched after android.app.Activity.onStart returns, Event.ON_STOP 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 or 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.

Extension functions

Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.

Last updated 2025-05-15 UTC.