Google 致力于为黑人社区推动种族平等。查看具体举措

LifecycleOwner

interface LifecycleOwner
androidx.lifecycle.LifecycleOwner

A class that has an Android lifecycle. These events can be used by custom components to handle lifecycle changes without implementing any code inside the Activity or the Fragment.

Summary

Public methods
abstract Lifecycle

Returns the Lifecycle of the provider.

Extension functions
From androidx.lifecycle
suspend T
LifecycleOwner.whenCreated(block: suspend CoroutineScope.() -> T)

Runs the given block when the LifecycleOwner's Lifecycle is at least in Lifecycle.State.CREATED state.

suspend T
LifecycleOwner.whenResumed(block: suspend CoroutineScope.() -> T)

Runs the given block when the LifecycleOwner's Lifecycle is at least in Lifecycle.State.RESUMED state.

suspend T
LifecycleOwner.whenStarted(block: suspend CoroutineScope.() -> T)

Runs the given block when the LifecycleOwner's Lifecycle is at least in Lifecycle.State.STARTED state.

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

Run block with this LifecycleOwner's Lifecycle in a Lifecycle.State of at least Lifecycle.State.CREATED and resume with the result.

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

Run block with this LifecycleOwner's Lifecycle in a Lifecycle.State of at least Lifecycle.State.RESUMED and resume with the result.

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

Run block with this LifecycleOwner's Lifecycle in a Lifecycle.State of at least Lifecycle.State.STARTED and resume with the result.

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

Run block with this LifecycleOwner's Lifecycle in a Lifecycle.State of at least state and resume with the result.

Extension properties
From androidx.lifecycle
LifecycleCoroutineScope

CoroutineScope tied to this LifecycleOwner's Lifecycle.

Public methods

getLifecycle

@NonNull abstract fun getLifecycle(): Lifecycle

Returns the Lifecycle of the provider.

Return
Lifecycle The lifecycle of the provider.