Lifecycle.Event


public enum Lifecycle.Event extends Enum


Represents a transition event triggered by a change in the LifecycleOwner's state.

Together with States, these events form a directed graph defining the valid lifecycle flow of a component:

           +-------------+
| INITIALIZED |
+-------------+
|
| ON_CREATE
v
+---------+
| CREATED | ----------+
+---------+ |
| ^ |
ON_START | | ON_STOP |
v | | ON_DESTROY
+---------+ |
| STARTED | |
+---------+ |
| ^ |
ON_RESUME | | ON_PAUSE |
v | v
+---------+ +-----------+
| RESUMED | | DESTROYED |
+---------+ +-----------+
See also
Lifecycle.State

for the states resulting from these transition events.

Summary

Enum Values

ON_ANY

A wildcard event constant that matches all Events.

ON_CREATE

Dispatched when the LifecycleOwner enters the created state.

ON_DESTROY

Dispatched when the LifecycleOwner is about to be destroyed.

ON_PAUSE

Dispatched when the LifecycleOwner is about to leave the resumed state.

ON_RESUME

Dispatched when the LifecycleOwner enters the resumed state.

ON_START

Dispatched when the LifecycleOwner enters the started state.

ON_STOP

Dispatched when the LifecycleOwner is about to leave the started state.

Public methods

static final Lifecycle.Event

Returns the Event that transitions down from the specified state to a lower state, or null if no transition exists.

static final Lifecycle.Event

Returns the Event that transitions down into the specified target state, or null if no transition exists.

final @NonNull EnumEntries<@NonNull Lifecycle.Event>

Returns an immutable kotlin.enums.EnumEntries list containing the constants of this enum type, in the order they're declared.

final @NonNull Lifecycle.State

Returns the new State of a Lifecycle that just reported this Event.

static final Lifecycle.Event

Returns the Event that transitions up from the specified state to a higher state, or null if no transition exists.

static final Lifecycle.Event

Returns the Event that transitions up into the specified target state, or null if no transition exists.

static final @NonNull Lifecycle.Event

Returns the enum constant of this type with the specified name.

static final @NonNull Lifecycle.Event[]

Returns an array containing the constants of this enum type, in the order they're declared.

Enum Values

ON_ANY

Lifecycle.Event Lifecycle.Event.ON_ANY

A wildcard event constant that matches all Events.

ON_CREATE

Lifecycle.Event Lifecycle.Event.ON_CREATE

Dispatched when the LifecycleOwner enters the created state.

Called after the LifecycleOwner's onCreate returns. Transitions the lifecycle to State.CREATED.

ON_DESTROY

Lifecycle.Event Lifecycle.Event.ON_DESTROY

Dispatched when the LifecycleOwner is about to be destroyed.

Called before the LifecycleOwner's onDestroy is called. Transitions the lifecycle to State.DESTROYED.

ON_PAUSE

Lifecycle.Event Lifecycle.Event.ON_PAUSE

Dispatched when the LifecycleOwner is about to leave the resumed state.

Called before the LifecycleOwner's onPause is called. Transitions the lifecycle to State.STARTED.

ON_RESUME

Lifecycle.Event Lifecycle.Event.ON_RESUME

Dispatched when the LifecycleOwner enters the resumed state.

Called after the LifecycleOwner's onResume returns. Transitions the lifecycle to State.RESUMED.

ON_START

Lifecycle.Event Lifecycle.Event.ON_START

Dispatched when the LifecycleOwner enters the started state.

Called after the LifecycleOwner's onStart returns. Transitions the lifecycle to State.STARTED.

ON_STOP

Lifecycle.Event Lifecycle.Event.ON_STOP

Dispatched when the LifecycleOwner is about to leave the started state.

Called before the LifecycleOwner's onStop is called. Transitions the lifecycle to State.CREATED.

Public methods

downFrom

Added in 2.6.0
public static final Lifecycle.Event downFrom(@NonNull Lifecycle.State state)

Returns the Event that transitions down from the specified state to a lower state, or null if no transition exists.

Given state Returned Event
State.DESTROYED null
State.INITIALIZED null
State.CREATED Event.ON_DESTROY
State.STARTED Event.ON_STOP
State.RESUMED Event.ON_PAUSE

downTo

Added in 2.6.0
public static final Lifecycle.Event downTo(@NonNull Lifecycle.State state)

Returns the Event that transitions down into the specified target state, or null if no transition exists.

Target state Returned Event
State.DESTROYED Event.ON_DESTROY
State.INITIALIZED null
State.CREATED Event.ON_STOP
State.STARTED Event.ON_PAUSE
State.RESUMED null

getEntries

public final @NonNull EnumEntries<@NonNull Lifecycle.EventgetEntries()

Returns an immutable kotlin.enums.EnumEntries list containing the constants of this enum type, in the order they're declared.

upFrom

Added in 2.6.0
public static final Lifecycle.Event upFrom(@NonNull Lifecycle.State state)

Returns the Event that transitions up from the specified state to a higher state, or null if no transition exists.

Given state Returned Event
State.DESTROYED null
State.INITIALIZED Event.ON_CREATE
State.CREATED Event.ON_START
State.STARTED Event.ON_RESUME
State.RESUMED null

upTo

Added in 2.6.0
public static final Lifecycle.Event upTo(@NonNull Lifecycle.State state)

Returns the Event that transitions up into the specified target state, or null if no transition exists.

Target state Returned Event
State.DESTROYED null
State.INITIALIZED null
State.CREATED Event.ON_CREATE
State.STARTED Event.ON_START
State.RESUMED Event.ON_RESUME

valueOf

Added in 2.0.0
public static final @NonNull Lifecycle.Event valueOf(@NonNull String value)

Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)

Throws
kotlin.IllegalArgumentException

if this enum type has no constant with the specified name

values

Added in 2.0.0
public static final @NonNull Lifecycle.Event[] values()

Returns an array containing the constants of this enum type, in the order they're declared.

This method may be used to iterate over the constants.

The function returns a new instance of the array on every call. The array could be mutated, so working with it may also require defensive copying. Consider using entries property as a more efficient alternative returning an immutable list of enum entries.