Lifecycle.State



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 functions

Boolean

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

Cmn
Lifecycle.State
valueOf(value: String)

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

Cmn
Array<Lifecycle.State>

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

Cmn

Public properties

EnumEntries<Lifecycle.State>

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

Cmn

Enum Values

CREATED

val Lifecycle.State.CREATEDLifecycle.State

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

val Lifecycle.State.DESTROYEDLifecycle.State

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

val Lifecycle.State.INITIALIZEDLifecycle.State

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

val Lifecycle.State.RESUMEDLifecycle.State

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

val Lifecycle.State.STARTEDLifecycle.State

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 functions

isAtLeast

fun isAtLeast(state: Lifecycle.State): Boolean

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

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

valueOf

fun valueOf(value: String): Lifecycle.State

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

fun values(): Array<Lifecycle.State>

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.

Public properties

entries

val entriesEnumEntries<Lifecycle.State>

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