dispatch-android-lifecycle

CoroutineScope functionality linked with an Android Lifecycle.

Contents

  • #types

  • #member-functions

  • #extension-functions

  • #minimum-gradle-config

Types

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

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:

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:

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.0")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.0")
implementation(platform("com.rickbusarow.dispatch:dispatch-bom:1.0.0-beta10"))
implementation("com.rickbusarow.dispatch:dispatch-android-lifecycle")
implementation("androidx.lifecycle:lifecycle-common:2.3.1")
}

Packages

Link copied to clipboard