Lifecycle
CoroutineScope functionality linked with an Android Lifecycle.
Types
| Name | Description |
|---|---|
| DispatchLifecycleScope | MainCoroutineScope with a Lifecycle, capable of automatically cancelling and restarting coroutines along with that lifecycle. |
| MinimumStatePolicy | Defines the behavior of a Lifecycle-aware Job when it passes below its minimum Lifecycle.State |
Member functions
| Name | Description |
|---|---|
| launchOnCreate | Creates a coroutine tied to a Lifecycle which will automatically enact a MinimumStatePolicy upon dropping below Lifecycle.State.CREATED |
| launchOnStart | Creates a coroutine tied to a Lifecycle which will automatically enact a MinimumStatePolicy upon dropping below Lifecycle.State.STARTED |
| launchOnResume | Creates a coroutine tied to a Lifecycle which will automatically enact a MinimumStatePolicy upon dropping below Lifecycle.State.RESUMED |
Extension functions
LifecycleOwner extension suspending functions:
| Name | Description |
|---|---|
| onNextCreate | Executes code one time upon reaching a state of Lifecycle.State.CREATED |
| onNextStart | Executes code one time upon reaching a state of Lifecycle.State.STARTED |
| onNextResume | Executes code one time upon reaching a state of Lifecycle.State.RESUMED |
Lifecycle extension suspending functions:
| Name | Description |
|---|---|
| onNextCreate | Executes code one time upon reaching a state of Lifecycle.State.CREATED |
| onNextStart | Executes code one time upon reaching a state of Lifecycle.State.STARTED |
| onNextResume | Executes 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-SNAPSHOT")
implementation("androidx.lifecycle:lifecycle-common:2.2.0")
}