Package-level declarations

Types

Link copied to clipboard

A LifecycleRegistry without the state checking, and has moveTo method to move to a specific state. This is a flexible version of LifecycleRegistry.

Link copied to clipboard
interface Lifecycle

A holder of Lifecycle.State that can be observed for changes.

Link copied to clipboard

A CancellationException that indicates that the Lifecycle associated with an operation reached the Lifecycle.State.DESTROYED state before the operation could complete.

Link copied to clipboard
interface LifecycleOwner

A class that has an lifecycle.

Link copied to clipboard

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

Link copied to clipboard

The CompositionLocal containing the current LifecycleOwner.

Properties

Link copied to clipboard

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

Functions

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
fun <T> Flow<T>.flowWithLifecycle(lifecycle: Lifecycle, minActiveState: Lifecycle.State = Lifecycle.State.STARTED): Flow<T>

Flow operator that emits values from this upstream Flow when the lifecycle is at least at minActiveState state. The emissions will be stopped when the lifecycle state falls below minActiveState state.

Link copied to clipboard

Creates a default implementation of LenientLifecycleRegistry.

Creates a default implementation of LenientLifecycleRegistry with the specified initialState.

Link copied to clipboard
Link copied to clipboard

Creates a default implementation of LifecycleRegistry.

Creates a default implementation of LifecycleRegistry with the specified initialState.

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.

suspend fun LifecycleOwner.repeatOnLifecycle(state: Lifecycle.State, block: suspend CoroutineScope.() -> Unit)

LifecycleOwner's extension function for Lifecycle.repeatOnLifecycle to allow an easier call to the API from LifecycleOwners such as Activities and Fragments.

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.

inline suspend fun <R> LifecycleOwner.withCreated(crossinline block: () -> R): R

Run block with this LifecycleOwner's 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.

inline suspend fun <R> LifecycleOwner.withResumed(crossinline block: () -> R): R

Run block with this LifecycleOwner's 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.

inline suspend fun <R> LifecycleOwner.withStarted(crossinline block: () -> R): R

Run block with this LifecycleOwner's 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.

inline suspend fun <R> LifecycleOwner.withStateAtLeast(state: Lifecycle.State, crossinline block: () -> R): R

Run block with this LifecycleOwner's 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.