LifecycleRegistry

Represents Lifecycle and Lifecycle.Observer at the same time. Can be used to manually control the Lifecycle.

Inheritors

Properties

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Creates a Flow of Events containing values dispatched by this Lifecycle.

Functions

Link copied to clipboard

Collects values from the Lifecycle.currentStateFlow and represents its latest value via State. The StateFlow.value is used as an initial value. Every time there would be new value posted into the StateFlow the returned State will be updated causing recomposition of every State.value usage.

Link copied to clipboard
abstract fun onStateChanged(event: Lifecycle.Event)
Link copied to clipboard
suspend fun Lifecycle.repeatOnLifecycle(state: Lifecycle.State, block: suspend CoroutineScope.() -> Unit)

Runs the given block in a new coroutine when this Lifecycle is at least at state and suspends the execution until this Lifecycle is Lifecycle.State.DESTROYED.

Link copied to clipboard
Link copied to clipboard
inline suspend fun <R> Lifecycle.withCreated(crossinline block: () -> R): R

Run block with this Lifecycle in a Lifecycle.State of at least Lifecycle.State.CREATED and resume with the result. Throws the CancellationException if the lifecycle has reached Lifecycle.State.DESTROYED by the time of the call or before block is able to run.

Link copied to clipboard
inline suspend fun <R> Lifecycle.withResumed(crossinline block: () -> R): R

Run block with this Lifecycle in a Lifecycle.State of at least Lifecycle.State.RESUMED and resume with the result. Throws the CancellationException if the lifecycle has reached Lifecycle.State.DESTROYED by the time of the call or before block is able to run.

Link copied to clipboard
inline suspend fun <R> Lifecycle.withStarted(crossinline block: () -> R): R

Run block with this Lifecycle in a Lifecycle.State of at least Lifecycle.State.STARTED and resume with the result. Throws the CancellationException if the lifecycle has reached Lifecycle.State.DESTROYED by the time of the call or before block is able to run.

Link copied to clipboard
inline suspend fun <R> Lifecycle.withStateAtLeast(state: Lifecycle.State, crossinline block: () -> R): R

Run block with this Lifecycle in a Lifecycle.State of at least state and resume with the result. Throws the CancellationException if the lifecycle has reached Lifecycle.State.DESTROYED by the time of the call or before block is able to run.