# LifecycleCoroutineScope

Artifact: [androidx.lifecycle:lifecycle-common](https://developer.android.com/jetpack/androidx/releases/lifecycle) [View Source](https://cs.android.com/search?q=file:androidx/lifecycle/Lifecycle.+class:androidx.lifecycle.LifecycleCoroutineScope) Added in [2.6.0](https://developer.android.com/jetpack/androidx/releases/lifecycle#2.6.0)

*** ** * ** ***

Common/AllAndroid/JVM
- Cmn

  ```
  abstract class LifecycleCoroutineScope : CoroutineScope
  ```

*** ** * ** ***

`https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope/index.html` tied to a `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle` and `Dispatchers.Main.immediate`.

Canceled when the `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle` is destroyed.

## Summary

| ### Public functions |
|---|---|---|
| `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-job/index.html` | `[launchWhenCreated](https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleCoroutineScope#launchWhenCreated(kotlin.coroutines.SuspendFunction1))(block: suspend https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope/index.html.() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)` **This function is deprecated.** launchWhenCreated is deprecated as it can lead to wasted resources in some cases. | android |
| `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-job/index.html` | `[launchWhenResumed](https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleCoroutineScope#launchWhenResumed(kotlin.coroutines.SuspendFunction1))(block: suspend https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope/index.html.() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)` **This function is deprecated.** launchWhenResumed is deprecated as it can lead to wasted resources in some cases. | android |
| `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-job/index.html` | `[launchWhenStarted](https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleCoroutineScope#launchWhenStarted(kotlin.coroutines.SuspendFunction1))(block: suspend https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope/index.html.() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)` **This function is deprecated.** launchWhenStarted is deprecated as it can lead to wasted resources in some cases. | android |

### Inherited properties

From [kotlinx.coroutines.CoroutineScope](https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope/index.html) `abstract https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-coroutine-context/index.html` `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope/coroutine-context.html` Cmn `abstract https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-coroutine-context/index.html` `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope/coroutine-context.html` android `abstract https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-coroutine-context/index.html` `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope/coroutine-context.html` Cmn

## Public functions

### launchWhenCreated

android Added in [2.6.0](https://developer.android.com/jetpack/androidx/releases/lifecycle#2.6.0) Deprecated in [2.6.0](https://developer.android.com/jetpack/androidx/releases/lifecycle#2.6.0)

```
fun [launchWhenCreated](https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleCoroutineScope#launchWhenCreated(kotlin.coroutines.SuspendFunction1))(block: suspend CoroutineScope.() -> Unit): Job
```

> [!CAUTION]
> **This function is deprecated.**   
> launchWhenCreated is deprecated as it can lead to wasted resources in some cases. Replace with suspending repeatOnLifecycle to run the block whenever the Lifecycle state is at least Lifecycle.State.CREATED.

Launches and runs the given block when the `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle` controlling this `https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleCoroutineScope` is at least in `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State#CREATED` state.

The returned `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-job/index.html` will be cancelled when the `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle` is destroyed.

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.Lifecycle).whenCreated(kotlin.coroutines.SuspendFunction1)` |   |
| `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.Lifecycle).coroutineScope()` |   |

### launchWhenResumed

android Added in [2.6.0](https://developer.android.com/jetpack/androidx/releases/lifecycle#2.6.0) Deprecated in [2.6.0](https://developer.android.com/jetpack/androidx/releases/lifecycle#2.6.0)

```
fun [launchWhenResumed](https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleCoroutineScope#launchWhenResumed(kotlin.coroutines.SuspendFunction1))(block: suspend CoroutineScope.() -> Unit): Job
```

> [!CAUTION]
> **This function is deprecated.**   
> launchWhenResumed is deprecated as it can lead to wasted resources in some cases. Replace with suspending repeatOnLifecycle to run the block whenever the Lifecycle state is at least Lifecycle.State.RESUMED.

Launches and runs the given block when the `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle` controlling this `https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleCoroutineScope` is at least in `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State#RESUMED` state.

The returned `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-job/index.html` will be cancelled when the `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle` is destroyed.

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.Lifecycle).whenResumed(kotlin.coroutines.SuspendFunction1)` |   |
| `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.Lifecycle).coroutineScope()` |   |

### launchWhenStarted

android Added in [2.6.0](https://developer.android.com/jetpack/androidx/releases/lifecycle#2.6.0) Deprecated in [2.6.0](https://developer.android.com/jetpack/androidx/releases/lifecycle#2.6.0)

```
fun [launchWhenStarted](https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleCoroutineScope#launchWhenStarted(kotlin.coroutines.SuspendFunction1))(block: suspend CoroutineScope.() -> Unit): Job
```

> [!CAUTION]
> **This function is deprecated.**   
> launchWhenStarted is deprecated as it can lead to wasted resources in some cases. Replace with suspending repeatOnLifecycle to run the block whenever the Lifecycle state is at least Lifecycle.State.STARTED.

Launches and runs the given block when the `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle` controlling this `https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleCoroutineScope` is at least in `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State#STARTED` state.

The returned `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-job/index.html` will be cancelled when the `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle` is destroyed.

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.Lifecycle).whenStarted(kotlin.coroutines.SuspendFunction1)` |   |
| `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.Lifecycle).coroutineScope()` |   |