Skip to main content
Version: 1.0.0-beta10

Lifecycle

CoroutineScope functionality linked with an Android Lifecycle.

Types

NameDescription
DispatchLifecycleScopeMainCoroutineScope with a Lifecycle, capable of automatically cancelling and restarting coroutines along with that lifecycle.
MinimumStatePolicyDefines the behavior of a Lifecycle-aware Job when it passes below its minimum Lifecycle.State

Member functions

NameDescription
launchOnCreateCreates a coroutine tied to a Lifecycle which will automatically enact a MinimumStatePolicy upon dropping below Lifecycle.State.CREATED
launchOnStartCreates a coroutine tied to a Lifecycle which will automatically enact a MinimumStatePolicy upon dropping below Lifecycle.State.STARTED
launchOnResumeCreates a coroutine tied to a Lifecycle which will automatically enact a MinimumStatePolicy upon dropping below Lifecycle.State.RESUMED

Extension functions

LifecycleOwner extension suspending functions:

NameDescription
onNextCreateExecutes code one time upon reaching a state of Lifecycle.State.CREATED
onNextStartExecutes code one time upon reaching a state of Lifecycle.State.STARTED
onNextResumeExecutes code one time upon reaching a state of Lifecycle.State.RESUMED

Lifecycle extension suspending functions:

NameDescription
onNextCreateExecutes code one time upon reaching a state of Lifecycle.State.CREATED
onNextStartExecutes code one time upon reaching a state of Lifecycle.State.STARTED
onNextResumeExecutes code one time upon reaching a state of Lifecycle.State.RESUMED

Minimum Gradle Config

Add to your module's build.gradle.kts:

repositories {
mavenCentral()
}

dependencies {

implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.2")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.2")
implementation("com.rickbusarow.dispatch:dispatch-android-lifecycle:1.0.0-beta10")
implementation("androidx.lifecycle:lifecycle-common:2.2.0")
}