Lifecycle.State


public enum Lifecycle.State extends Enum


Represents the current lifecycle state of a LifecycleOwner.

You can visualize these states as nodes in a graph where Events represent the directed edges guiding transitions between them:

           +-------------+
| INITIALIZED |
+-------------+
|
| ON_CREATE
v
+---------+
| CREATED | ----------+
+---------+ |
| ^ |
ON_START | | ON_STOP |
v | | ON_DESTROY
+---------+ |
| STARTED | |
+---------+ |
| ^ |
ON_RESUME | | ON_PAUSE |
v | v
+---------+ +-----------+
| RESUMED | | DESTROYED |
+---------+ +-----------+

Transitions between these states occur strictly sequentially. When moving between non-adjacent states, the registry dispatches all intermediate Events. For example, transitioning from State.RESUMED to State.DESTROYED will sequentially dispatch Event.ON_PAUSE, Event.ON_STOP, and Event.ON_DESTROY.

See also
Lifecycle.Event

for the transition events between these states.

Summary

Enum Values

CREATED

Created state for a LifecycleOwner.

DESTROYED

Destroyed state for a LifecycleOwner.

INITIALIZED

Initialized state for a LifecycleOwner.

RESUMED

Resumed state for a LifecycleOwner.

STARTED

Started state for a LifecycleOwner.

Public methods

final @NonNull EnumEntries<@NonNull Lifecycle.State>

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

final boolean

Returns true if this state is greater than or equal to the given state.

static final @NonNull Lifecycle.State

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

static final @NonNull Lifecycle.State[]

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

Enum Values

CREATED

Lifecycle.State Lifecycle.State.CREATED

Created state for a LifecycleOwner.

This is a cyclic state. The lifecycle can transition back and forth between CREATED, STARTED, and RESUMED states.

For instance, for an Android Activity, this state is reached after the activity's onCreate returns, or right before onStop is called.

DESTROYED

Lifecycle.State Lifecycle.State.DESTROYED

Destroyed state for a LifecycleOwner.

This is the terminal state. Once reached, this Lifecycle will not dispatch any more events, and it cannot transition to any other state.

For instance, for an Android Activity, this state is reached right before the activity's onDestroy is called.

INITIALIZED

Lifecycle.State Lifecycle.State.INITIALIZED

Initialized state for a LifecycleOwner.

This is the initial state. Once the lifecycle transitions out of this state, it cannot transition back to it.

For instance, for an Android Activity, this is the state when it is constructed but has not received onCreate yet.

RESUMED

Lifecycle.State Lifecycle.State.RESUMED

Resumed state for a LifecycleOwner.

This is a cyclic state. The lifecycle can transition back and forth between CREATED, STARTED, and RESUMED states.

For instance, for an Android Activity, this state is reached after the activity's onResume returns.

STARTED

Lifecycle.State Lifecycle.State.STARTED

Started state for a LifecycleOwner.

This is a cyclic state. The lifecycle can transition back and forth between CREATED, STARTED, and RESUMED states.

For instance, for an Android Activity, this state is reached after the activity's onStart returns, or right before onPause is called.

Public methods

getEntries

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

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

isAtLeast

Added in 2.0.0
public final boolean isAtLeast(@NonNull Lifecycle.State state)

Returns true if this state is greater than or equal to the given state.

States are ordered as DESTROYED<INITIALIZED<CREATED<STARTED<RESUMED.

valueOf

Added in 2.0.0
public static final @NonNull Lifecycle.State 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.State[] 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.