# androidx.lifecycle

*** ** * ** ***

Common/AllAndroid/JVM

## Interfaces

|---|---|---|
| `https://developer.android.com/reference/kotlin/androidx/lifecycle/DefaultLifecycleObserver` | Callback interface for listening to `https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleOwner` state changes. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/lifecycle/HasDefaultViewModelProviderFactory` | An interface marking a `https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModelStoreOwner` as having a default `https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModelProvider.Factory` for use with `https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModelProvider`. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleEventObserver` | Interface for receiving any `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.Event` state changes. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleObserver` | Marker interface that indicates a class is a `https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleObserver`. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleOwner` | A class that exposes a `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle`. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleRegistryOwner` | **This interface is deprecated.** Use `androidx.appcompat.app.AppCompatActivity` which extends `https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleOwner`, so there are no use cases for this class. <br /> | android |
| `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveDataScope` | Interface that allows controlling a `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData` from a coroutine block. | android |
| `https://developer.android.com/reference/kotlin/androidx/lifecycle/Observer` | A simple callback that can receive from `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData`. | android |
| `https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModelProvider.Factory` | Implementations of the `https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModelProvider.Factory` interface are responsible for instantiating `https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModel`s. | Cmn android |
| `https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModelStoreOwner` | A scope that owns a `https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModelStore`. | Cmn |

## Classes

|---|---|---|
| `https://developer.android.com/reference/kotlin/androidx/lifecycle/AbstractSavedStateViewModelFactory` | **This class is deprecated.** Use \`viewModelFactory\` or implement \`ViewModelProvider.Factory\`, combined with \`CreationExtras.createSavedStateHandle()\`. | android |
| `https://developer.android.com/reference/kotlin/androidx/lifecycle/AndroidViewModel` | `https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModel` that has access to the `https://developer.android.com/reference/android/app/Application.html` context. | android |
| `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle` | Defines an object with a lifecycle state control flow. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleCoroutineScope` | `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`. | Cmn android |
| `https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleRegistry` | A `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle` implementation that manages multiple `https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleObserver`s. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleService` | A Service that is also a `https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleOwner`. | android |
| `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData` | LiveData is a data holder class that can be observed within a given lifecycle. | android |
| `https://developer.android.com/reference/kotlin/androidx/lifecycle/MediatorLiveData` | `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData` subclass which may observe other `LiveData` objects and react on `OnChanged` events from them. | android |
| `https://developer.android.com/reference/kotlin/androidx/lifecycle/MutableLiveData` | `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData` which publicly exposes `https://developer.android.com/reference/kotlin/androidx/lifecycle/MutableLiveData#setValue(T)` and `https://developer.android.com/reference/kotlin/androidx/lifecycle/MutableLiveData#postValue(T)` method. | android |
| `https://developer.android.com/reference/kotlin/androidx/lifecycle/ProcessLifecycleInitializer` | Initializes `https://developer.android.com/reference/kotlin/androidx/lifecycle/ProcessLifecycleOwner` using `androidx.startup`. | android |
| `https://developer.android.com/reference/kotlin/androidx/lifecycle/ProcessLifecycleOwner` | Class that provides lifecycle for the whole application process. | android |
| `https://developer.android.com/reference/kotlin/androidx/lifecycle/SavedStateHandle` | A handle to saved state passed to `https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModel`. | Cmn android |
| `https://developer.android.com/reference/kotlin/androidx/lifecycle/SavedStateViewModelFactory` | A `https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModelProvider.Factory` that creates `https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModel`s with access to a `https://developer.android.com/reference/kotlin/androidx/lifecycle/SavedStateHandle` in their constructor. | Cmn android |
| `https://developer.android.com/reference/kotlin/androidx/lifecycle/ServiceLifecycleDispatcher` | Helper class to dispatch lifecycle events for a Service. | android |
| `https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModel` | Prepares and manages data for the UI. | Cmn android |
| `https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModelLazy` | An implementation of `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-lazy/index.html` to facilitate lazy retrieval of `https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModel` instances. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModelProvider` | A utility class that manages the lifecycle, caching, and instantiation of `https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModel` instances. | Cmn android |
| `https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModelProvider.AndroidViewModelFactory` | Factory that creates `https://developer.android.com/reference/kotlin/androidx/lifecycle/AndroidViewModel` and `https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModel` instances. | android |
| `https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModelProvider.NewInstanceFactory` | Factory that creates `https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModel` instances by calling their no-argument constructor. | android |
| `https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModelProvider.NewInstanceFactory` | Simple factory, which calls empty constructor on the give class. | android |
| `https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModelProviders` | **This class is deprecated.** Use the constructors for `https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModelProvider` directly. <br /> | android |
| `https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModelProviders.DefaultFactory` | **This class is deprecated.** Use ViewModelProvider.AndroidViewModelFactory <br /> | android |
| `https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModelStore` | Stores `https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModel` instances by key. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModelStores` | **This class is deprecated.** Use `https://developer.android.com/reference/kotlin/androidx/activity/ComponentActivity#getViewModelStore()` or `https://developer.android.com/reference/kotlin/androidx/fragment/app/Fragment#getViewModelStore()` to retrieve a `ViewModelStore` directly from activities and fragments. <br /> | android |

## Exceptions

|---|---|---|
| `https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleDestroyedException` | A `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-cancellation-exception/index.html` that indicates that the `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle` associated with an operation reached the `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State#DESTROYED` state before the operation could complete. | Cmn |

## Objects

|---|---|---|
| `https://developer.android.com/reference/kotlin/androidx/lifecycle/SavedStateHandle.Companion` |   | Cmn android |
| `https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModelProvider.NewInstanceFactory.Companion` |   | android |

## Annotations

|---|---|---|
| `https://developer.android.com/reference/kotlin/androidx/lifecycle/OnLifecycleEvent` | **This annotation is deprecated.** This annotation required the usage of code generation or reflection, which should be avoided. <br /> | android |

## Enums

|---|---|---|
| `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.Event` | Represents a transition event triggered by a change in the `https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleOwner`'s state. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State` | Represents the current lifecycle state of a `https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleOwner`. | Cmn |

## Top-level functions summary

|---|---|---|
| `https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleOwner` | `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#LifecycleOwner(androidx.lifecycle.Lifecycle)(lifecycle: https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle)` Creates a `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#LifecycleOwner(androidx.lifecycle.Lifecycle)` directly backed by the provided `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle`. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData<T>` | `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#liveData(kotlin.coroutines.CoroutineContext,kotlin.Long,kotlin.coroutines.SuspendFunction1)( context: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-coroutine-context/index.html, timeoutInMs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html, block: suspend https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveDataScope<T>.() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html )` Builds a LiveData that has values yielded from the given `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#liveData(kotlin.coroutines.CoroutineContext,kotlin.Long,kotlin.coroutines.SuspendFunction1)` that executes on a `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveDataScope`. | android |
| `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData<T>` | `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresApi(value = 26) <T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#liveData(java.time.Duration,kotlin.coroutines.CoroutineContext,kotlin.coroutines.SuspendFunction1)( timeout: https://developer.android.com/reference/java/time/Duration.html, context: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-coroutine-context/index.html, block: suspend https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveDataScope<T>.() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html )` Builds a LiveData that has values yielded from the given `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#liveData(java.time.Duration,kotlin.coroutines.CoroutineContext,kotlin.coroutines.SuspendFunction1)` that executes on a `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveDataScope`. | android |
| `https://www.reactive-streams.org/reactive-streams-1.0.4-javadoc/org/reactivestreams/Publisher.html<T>` | `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> [toPublisher](https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#toPublisher(androidx.lifecycle.LifecycleOwner,androidx.lifecycle.LiveData))(lifecycle: https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleOwner, liveData: https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData<T>)` **This function is deprecated.** Use the extension method \`liveData.toPublisher(lifecycleOwner)\` instead. | android |

## Extension functions summary

|---|---|---|
| `inline https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleObserver` | `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.Lifecycle).addObserver(kotlin.Function3)( crossinline action: https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleObserver.(source: https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleOwner, event: https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.Event) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html )` Adds a `https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleObserver` to this `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle` using the provided `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.Lifecycle).addObserver(kotlin.Function3)`. | Cmn |
| `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html<T>` | `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData<T>.https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.LiveData).asFlow()()` Creates a `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html` containing values dispatched by originating `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData`: at the start a flow collector receives the latest value held by LiveData and then observes LiveData updates. | android |
| `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData<T>` | `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html<T>.https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(kotlinx.coroutines.flow.Flow).asLiveData(kotlin.coroutines.CoroutineContext,kotlin.Long)(context: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-coroutine-context/index.html, timeoutInMs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)` Creates a LiveData that has values collected from the origin `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html`. | android |
| `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData<T>` | `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresApi(value = 26) <T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html<T>.https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(kotlinx.coroutines.flow.Flow).asLiveData(java.time.Duration,kotlin.coroutines.CoroutineContext)(timeout: https://developer.android.com/reference/java/time/Duration.html, context: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-coroutine-context/index.html)` Creates a LiveData that has values collected from the origin `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html`. | android |
| `https://developer.android.com/reference/kotlin/androidx/lifecycle/SavedStateHandle` | `@https://developer.android.com/reference/kotlin/androidx/annotation/MainThread https://developer.android.com/reference/kotlin/androidx/lifecycle/viewmodel/CreationExtras.https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.viewmodel.CreationExtras).createSavedStateHandle()()` Creates a `https://developer.android.com/reference/kotlin/androidx/lifecycle/SavedStateHandle` for use in your `https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModel`s. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData<X>` | `@https://developer.android.com/reference/kotlin/androidx/annotation/MainThread <X : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData<X>.https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.LiveData).distinctUntilChanged()()` Creates a new `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData` object does not emit a value until the source `this` LiveData value has been changed. | android |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `@https://developer.android.com/reference/kotlin/androidx/annotation/MainThread <T : https://developer.android.com/reference/kotlin/androidx/savedstate/SavedStateRegistryOwner & https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModelStoreOwner> T.https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.savedstate.SavedStateRegistryOwner).enableSavedStateHandles()( )` Enables support for `https://developer.android.com/reference/kotlin/androidx/lifecycle/SavedStateHandle` in a component. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleOwner?` | `https://developer.android.com/reference/android/view/View.html.https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(android.view.View).findViewTreeLifecycleOwner()()` Retrieve the `https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleOwner` responsible for managing the given `https://developer.android.com/reference/android/view/View.html`. | android |
| `https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModelStoreOwner?` | `https://developer.android.com/reference/android/view/View.html.https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(android.view.View).findViewTreeViewModelStoreOwner()()` Retrieves the `https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModelStoreOwner` associated with the given `https://developer.android.com/reference/android/view/View.html`. | android |
| `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html<T>` | `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html<T>.https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(kotlinx.coroutines.flow.Flow).flowWithLifecycle(androidx.lifecycle.Lifecycle,androidx.lifecycle.Lifecycle.State)( lifecycle: https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle, minActiveState: https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State )` Flow operator that emits values from `this` upstream Flow when the `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(kotlinx.coroutines.flow.Flow).flowWithLifecycle(androidx.lifecycle.Lifecycle,androidx.lifecycle.Lifecycle.State)` is at least at `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(kotlinx.coroutines.flow.Flow).flowWithLifecycle(androidx.lifecycle.Lifecycle,androidx.lifecycle.Lifecycle.State)` state. | Cmn |
| `inline VM` | `@https://developer.android.com/reference/kotlin/androidx/annotation/MainThread <VM : https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModel> https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModelProvider.https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.ViewModelProvider).get()()` Returns an existing ViewModel or creates a new one in the scope (usually, a fragment or an activity), associated with this `ViewModelProvider`. | Cmn |
| `inline VM` | `@https://developer.android.com/reference/kotlin/androidx/annotation/MainThread <VM : https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModel> https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModelProvider.https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.ViewModelProvider).get(kotlin.String)(key: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)` Returns an existing ViewModel or creates a new one in the scope (usually, a fragment or an activity), associated with this `ViewModelProvider` and the given `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.ViewModelProvider).get(kotlin.String)`. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData<Y>` | `@https://developer.android.com/reference/kotlin/androidx/annotation/MainThread <X : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?, Y : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData<X>.https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.LiveData).map(kotlin.Function1)(transform: (X) -> Y)` Returns a `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData` mapped from `this` LiveData by applying `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.LiveData).map(kotlin.Function1)` to each value set on `this` LiveData. | android |
| `inline https://developer.android.com/reference/kotlin/androidx/lifecycle/Observer<T>` | `@https://developer.android.com/reference/kotlin/androidx/annotation/MainThread <T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData<T>.[observe](https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.LiveData).observe(androidx.lifecycle.LifecycleOwner,kotlin.Function1))( owner: https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleOwner, crossinline onChanged: (T) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html )` **This function is deprecated.** This extension method is not required when using Kotlin 1.4. | android |
| `suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.Lifecycle).repeatOnLifecycle(androidx.lifecycle.Lifecycle.State,kotlin.coroutines.SuspendFunction1)( state: https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State, 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 )` Runs the given `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.Lifecycle).repeatOnLifecycle(androidx.lifecycle.Lifecycle.State,kotlin.coroutines.SuspendFunction1)` in a new coroutine when `this` `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle` is at least at `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.Lifecycle).repeatOnLifecycle(androidx.lifecycle.Lifecycle.State,kotlin.coroutines.SuspendFunction1)` and suspends the execution until `this` `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle` is `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State#DESTROYED`. | Cmn |
| `suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleOwner.https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.LifecycleOwner).repeatOnLifecycle(androidx.lifecycle.Lifecycle.State,kotlin.coroutines.SuspendFunction1)( state: https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State, 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 )` `https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleOwner`'s extension function for `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.Lifecycle).repeatOnLifecycle(androidx.lifecycle.Lifecycle.State,kotlin.coroutines.SuspendFunction1)` to allow an easier call to the API from LifecycleOwners such as Activities and Fragments. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/android/view/View.html.https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(android.view.View).setViewTreeLifecycleOwner(androidx.lifecycle.LifecycleOwner)(lifecycleOwner: https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleOwner?)` Set the `https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleOwner` responsible for managing the given `https://developer.android.com/reference/android/view/View.html`. | android |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/android/view/View.html.https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(android.view.View).setViewTreeViewModelStoreOwner(androidx.lifecycle.ViewModelStoreOwner)( viewModelStoreOwner: https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModelStoreOwner? )` Sets the `https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModelStoreOwner` associated with the given `https://developer.android.com/reference/android/view/View.html`. | android |
| `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData<Y>` | `@https://developer.android.com/reference/kotlin/androidx/annotation/MainThread <X : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?, Y : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData<X>.https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.LiveData).switchMap(kotlin.Function1)(transform: (X) -> https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData<Y>?)` Returns a `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData` mapped from the input `this` `LiveData` by applying `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.LiveData).switchMap(kotlin.Function1)` to each value set on `this`. | android |
| `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData<T>` | `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> https://www.reactive-streams.org/reactive-streams-1.0.4-javadoc/org/reactivestreams/Publisher.html<T>.https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(org.reactivestreams.Publisher).toLiveData()()` Creates an observable `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData` stream from a ReactiveStreams `https://www.reactive-streams.org/reactive-streams-1.0.4-javadoc/org/reactivestreams/Publisher.html`}. | android |
| `https://www.reactive-streams.org/reactive-streams-1.0.4-javadoc/org/reactivestreams/Publisher.html<T>` | `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData<T>.https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.LiveData).toPublisher(androidx.lifecycle.LifecycleOwner)(lifecycle: https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleOwner)` Adapts the given `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData` stream to a ReactiveStreams `https://www.reactive-streams.org/reactive-streams-1.0.4-javadoc/org/reactivestreams/Publisher.html`. | android |
| `suspend T` | `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleOwner.[whenCreated](https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.LifecycleOwner).whenCreated(kotlin.coroutines.SuspendFunction1))(block: suspend https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope/index.html.() -> T)` **This function is deprecated.** whenCreated has been deprecated because it runs the block on a pausing dispatcher that suspends, rather than cancels work when the lifecycle state goes below the given state. | android |
| `suspend T` | `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.[whenCreated](https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.Lifecycle).whenCreated(kotlin.coroutines.SuspendFunction1))(block: suspend https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope/index.html.() -> T)` **This function is deprecated.** whenCreated has been deprecated because it runs the block on a pausing dispatcher that suspends, rather than cancels work when the lifecycle state goes below the given state. | android |
| `suspend T` | `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleOwner.[whenResumed](https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.LifecycleOwner).whenResumed(kotlin.coroutines.SuspendFunction1))(block: suspend https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope/index.html.() -> T)` **This function is deprecated.** whenResumed has been deprecated because it runs the block on a pausing dispatcher that suspends, rather than cancels work when the lifecycle state goes below the given state. | android |
| `suspend T` | `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.[whenResumed](https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.Lifecycle).whenResumed(kotlin.coroutines.SuspendFunction1))(block: suspend https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope/index.html.() -> T)` **This function is deprecated.** whenResumed has been deprecated because it runs the block on a pausing dispatcher that suspends, rather than cancels work when the lifecycle state goes below the given state. | android |
| `suspend T` | `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleOwner.[whenStarted](https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.LifecycleOwner).whenStarted(kotlin.coroutines.SuspendFunction1))(block: suspend https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope/index.html.() -> T)` **This function is deprecated.** whenStarted has been deprecated because it runs the block on a pausing dispatcher that suspends, rather than cancels work when the lifecycle state goes below the given state. | android |
| `suspend T` | `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.[whenStarted](https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.Lifecycle).whenStarted(kotlin.coroutines.SuspendFunction1))(block: suspend https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope/index.html.() -> T)` **This function is deprecated.** whenStarted has been deprecated because it runs the block on a pausing dispatcher that suspends, rather than cancels work when the lifecycle state goes below the given state. | android |
| `suspend T` | `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.[whenStateAtLeast](https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.Lifecycle).whenStateAtLeast(androidx.lifecycle.Lifecycle.State,kotlin.coroutines.SuspendFunction1))( minState: https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State, block: suspend https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope/index.html.() -> T )` **This function is deprecated.** whenStateAtLeast has been deprecated because it runs the block on a pausing dispatcher that suspends, rather than cancels work when the lifecycle state goes below the given state. | android |
| `suspend inline R` | `<R : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.Lifecycle).withCreated(kotlin.Function0)(crossinline block: () -> R)` Run `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.Lifecycle).withCreated(kotlin.Function0)` with this `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle` in a `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State` of at least `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State#CREATED` and resume with the result. | Cmn |
| `suspend inline R` | `<R : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleOwner.https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.LifecycleOwner).withCreated(kotlin.Function0)(crossinline block: () -> R)` Run `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.LifecycleOwner).withCreated(kotlin.Function0)` with this `https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleOwner`'s `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle` in a `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State` of at least `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State#CREATED` and resume with the result. | Cmn |
| `suspend inline R` | `<R : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.Lifecycle).withResumed(kotlin.Function0)(crossinline block: () -> R)` Run `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.Lifecycle).withResumed(kotlin.Function0)` with this `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle` in a `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State` of at least `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State#RESUMED` and resume with the result. | Cmn |
| `suspend inline R` | `<R : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleOwner.https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.LifecycleOwner).withResumed(kotlin.Function0)(crossinline block: () -> R)` Run `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.LifecycleOwner).withResumed(kotlin.Function0)` with this `https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleOwner`'s `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle` in a `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State` of at least `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State#RESUMED` and resume with the result. | Cmn |
| `suspend inline R` | `<R : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.Lifecycle).withStarted(kotlin.Function0)(crossinline block: () -> R)` Run `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.Lifecycle).withStarted(kotlin.Function0)` with this `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle` in a `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State` of at least `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State#STARTED` and resume with the result. | Cmn |
| `suspend inline R` | `<R : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleOwner.https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.LifecycleOwner).withStarted(kotlin.Function0)(crossinline block: () -> R)` Run `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.LifecycleOwner).withStarted(kotlin.Function0)` with this `https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleOwner`'s `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle` in a `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State` of at least `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State#STARTED` and resume with the result. | Cmn |
| `suspend inline R` | `<R : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.Lifecycle).withStateAtLeast(androidx.lifecycle.Lifecycle.State,kotlin.Function0)( state: https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State, crossinline block: () -> R )` Run `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.Lifecycle).withStateAtLeast(androidx.lifecycle.Lifecycle.State,kotlin.Function0)` with this `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle` in a `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State` of at least `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.Lifecycle).withStateAtLeast(androidx.lifecycle.Lifecycle.State,kotlin.Function0)` and resume with the result. | Cmn |
| `suspend inline R` | `<R : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleOwner.https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.LifecycleOwner).withStateAtLeast(androidx.lifecycle.Lifecycle.State,kotlin.Function0)( state: https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State, crossinline block: () -> R )` Run `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.LifecycleOwner).withStateAtLeast(androidx.lifecycle.Lifecycle.State,kotlin.Function0)` with this `https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleOwner`'s `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle` in a `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State` of at least `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.LifecycleOwner).withStateAtLeast(androidx.lifecycle.Lifecycle.State,kotlin.Function0)` and resume with the result. | Cmn |

## Top-level properties summary

|---|---|---|
| `https://developer.android.com/reference/kotlin/androidx/lifecycle/viewmodel/CreationExtras.Key<https://developer.android.com/reference/kotlin/androidx/savedstate/SavedState>` | `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#DEFAULT_ARGS_KEY()` A `https://developer.android.com/reference/kotlin/androidx/lifecycle/viewmodel/CreationExtras.Key` to retrieve the default `https://developer.android.com/reference/kotlin/androidx/savedstate/SavedState` arguments to be passed to the `https://developer.android.com/reference/kotlin/androidx/lifecycle/SavedStateHandle`. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/lifecycle/viewmodel/CreationExtras.Key<https://developer.android.com/reference/kotlin/androidx/savedstate/SavedStateRegistryOwner>` | `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#SAVED_STATE_REGISTRY_OWNER_KEY()` A `https://developer.android.com/reference/kotlin/androidx/lifecycle/viewmodel/CreationExtras.Key` to retrieve the `https://developer.android.com/reference/kotlin/androidx/savedstate/SavedStateRegistryOwner` associated with the `https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModel` being created. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/lifecycle/viewmodel/CreationExtras.Key<https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModelStoreOwner>` | `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#VIEW_MODEL_STORE_OWNER_KEY()` A `https://developer.android.com/reference/kotlin/androidx/lifecycle/viewmodel/CreationExtras.Key` to retrieve the `https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModelStoreOwner` associated with the `https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModel` being created. | Cmn |

## Extension properties summary

|---|---|---|
| `https://developer.android.com/reference/android/app/Application.html` | `https://developer.android.com/reference/kotlin/androidx/lifecycle/AndroidViewModel.https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.AndroidViewModel).application()` Returns the underlying `https://developer.android.com/reference/android/app/Application.html` of the `https://developer.android.com/reference/kotlin/androidx/lifecycle/AndroidViewModel`. | android |
| `https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleCoroutineScope` | `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.Lifecycle).coroutineScope()` `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope/index.html` tied to this `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle`. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/lifecycle/viewmodel/CreationExtras` | `https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModelStoreOwner?.https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.ViewModelStoreOwner).defaultViewModelCreationExtras()` Returns the appropriate default `https://developer.android.com/reference/kotlin/androidx/lifecycle/viewmodel/CreationExtras` to use. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModelProvider.Factory` | `https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModelStoreOwner?.https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.ViewModelStoreOwner).defaultViewModelProviderFactory()` Returns the appropriate default `https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModelProvider.Factory` to use. | Cmn |
| `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html<https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.Event>` | `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.Lifecycle).eventFlow()` Creates a `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html` of `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.Event`s dispatched by this `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle`. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleCoroutineScope` | `https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleOwner.https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.LifecycleOwner).lifecycleScope()` `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope/index.html` tied to this `https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleOwner`'s `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle`. | Cmn |
| `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope/index.html` | `https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModel.https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.ViewModel).viewModelScope()` The `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope/index.html` associated with this `https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModel`. | Cmn |

## Top-level functions

### LifecycleOwner

Cmn Artifact: [androidx.lifecycle:lifecycle-common](https://developer.android.com/jetpack/androidx/releases/lifecycle) [View Source](https://cs.android.com/search?q=file:androidx/lifecycle/LifecycleOwnerFactory.kt+function:LifecycleOwner) Added in [2.11.0](https://developer.android.com/jetpack/androidx/releases/lifecycle#2.11.0)

```
fun LifecycleOwner(lifecycle: Lifecycle): LifecycleOwner
```

Creates a `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#LifecycleOwner(androidx.lifecycle.Lifecycle)` directly backed by the provided `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle`.

### liveData

android Artifact: [androidx.lifecycle:lifecycle-livedata](https://developer.android.com/jetpack/androidx/releases/lifecycle) [View Source](https://cs.android.com/search?q=file:androidx/lifecycle/CoroutineLiveData.kt+function:liveData) Added in [2.7.0](https://developer.android.com/jetpack/androidx/releases/lifecycle#2.7.0)

```
fun <T : Any?> liveData(
    context: CoroutineContext = EmptyCoroutineContext,
    timeoutInMs: Long = DEFAULT_TIMEOUT,
    block: suspend LiveDataScope<T>.() -> Unit
): LiveData<T>
```

Builds a LiveData that has values yielded from the given `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#liveData(kotlin.coroutines.CoroutineContext,kotlin.Long,kotlin.coroutines.SuspendFunction1)` that executes on a `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveDataScope`.

The `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#liveData(kotlin.coroutines.CoroutineContext,kotlin.Long,kotlin.coroutines.SuspendFunction1)` starts executing when the returned `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData` becomes LiveData.onActive. If the `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData` becomes LiveData.onInactive while the `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#liveData(kotlin.coroutines.CoroutineContext,kotlin.Long,kotlin.coroutines.SuspendFunction1)` is executing, it will be cancelled after `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#liveData(kotlin.coroutines.CoroutineContext,kotlin.Long,kotlin.coroutines.SuspendFunction1)` milliseconds unless the `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData` becomes active again before that timeout (to gracefully handle cases like Activity rotation). Any value `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveDataScope#emit(kotlin.Any)`ed from a cancelled `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#liveData(kotlin.coroutines.CoroutineContext,kotlin.Long,kotlin.coroutines.SuspendFunction1)` will be ignored.

After a cancellation, if the `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData` becomes active again, the `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#liveData(kotlin.coroutines.CoroutineContext,kotlin.Long,kotlin.coroutines.SuspendFunction1)` will be re-executed from the beginning. If you would like to continue the operations based on where it was stopped last, you can use the `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveDataScope#latestValue()` function to get the last `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveDataScope#emit(kotlin.Any)`ed value.

If the `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#liveData(kotlin.coroutines.CoroutineContext,kotlin.Long,kotlin.coroutines.SuspendFunction1)` completes successfully *or* is cancelled due to reasons other than `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData` becoming inactive, it *will not* be re-executed even after `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData` goes through active inactive cycle.

As a best practice, it is important for the `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#liveData(kotlin.coroutines.CoroutineContext,kotlin.Long,kotlin.coroutines.SuspendFunction1)` to cooperate in cancellation. See kotlin coroutines documentation for details https://kotlinlang.org/docs/reference/coroutines/cancellation-and-timeouts.html.

The `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#liveData(kotlin.coroutines.CoroutineContext,kotlin.Long,kotlin.coroutines.SuspendFunction1)` can be changed to fit different use cases better, for example increasing it will give more time to the `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#liveData(kotlin.coroutines.CoroutineContext,kotlin.Long,kotlin.coroutines.SuspendFunction1)` to complete even if `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData` is inactive. It is good for cases when `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#liveData(kotlin.coroutines.CoroutineContext,kotlin.Long,kotlin.coroutines.SuspendFunction1)` is finite (meaning it can complete successfully) and is costly to restart. Otherwise if a `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#liveData(kotlin.coroutines.CoroutineContext,kotlin.Long,kotlin.coroutines.SuspendFunction1)` is cheap to restart, decreasing the `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#liveData(kotlin.coroutines.CoroutineContext,kotlin.Long,kotlin.coroutines.SuspendFunction1)` value will allow to yield less values that aren't consumed by anything.

```kotlin
// a simple LiveData that receives value 3, 3 seconds after being observed for the first time.
val data : LiveData<Int> = liveData {
    delay(3000)
    emit(3)
}


// a LiveData that fetches a `User` object based on a `userId` and refreshes it every 30 seconds
// as long as it is observed
val userId : LiveData<String> = ...
val user = userId.switchMap { id ->
    liveData {
      while(true) {
        // note that `while(true)` is fine because the `delay(30_000)` below will cooperate in
        // cancellation if LiveData is not actively observed anymore
        val data = api.fetch(id) // errors are ignored for brevity
        emit(data)
        delay(30_000)
      }
    }
}

// A retrying data fetcher with doubling back-off
val user = liveData {
    var backOffTime = 1_000
    var succeeded = false
    while(!succeeded) {
        try {
            emit(api.fetch(id))
            succeeded = true
        } catch(ioError : IOException) {
            delay(backOffTime)
            backOffTime *= minOf(backOffTime * 2, 60_000)
        }
    }
}

// a LiveData that tries to load the `User` from local cache first and then tries to fetch
// from the server and also yields the updated value
val user = liveData {
    // dispatch loading first
    emit(LOADING(id))
    // check local storage
    val cached = cache.loadUser(id)
    if (cached != null) {
        emit(cached)
    }
    if (cached == null || cached.isStale()) {
        val fresh = api.fetch(id) // errors are ignored for brevity
        cache.save(fresh)
        emit(fresh)
    }
}

// a LiveData that immediately receives a LiveData<User> from the database and yields it as a
// source but also tries to back-fill the database from the server
val user = liveData {
    val fromDb: LiveData<User> = roomDatabase.loadUser(id)
    emitSource(fromDb)
    val updated = api.fetch(id) // errors are ignored for brevity
    // Since we are using Room here, updating the database will update the `fromDb` LiveData
    // that was obtained above. See Room's documentation for more details.
    // https://developer.android.com/training/data-storage/room/accessing-data#query-observable
    roomDatabase.insert(updated)
}
```

| Parameters |
|---|---|
| `context: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-coroutine-context/index.html = EmptyCoroutineContext` | The CoroutineContext to run the given block in. Defaults to `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-empty-coroutine-context/index.html` combined with `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-main-coroutine-dispatcher/immediate.html` |
| `timeoutInMs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html = DEFAULT_TIMEOUT` | The timeout in ms before cancelling the block if there are no active observers (`https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData#hasActiveObservers()`. Defaults to `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#DEFAULT_TIMEOUT()`. |
| `block: suspend https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveDataScope<T>.() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | The block to run when the `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData` has active observers. |

### liveData

android Artifact: [androidx.lifecycle:lifecycle-livedata](https://developer.android.com/jetpack/androidx/releases/lifecycle) [View Source](https://cs.android.com/search?q=file:androidx/lifecycle/CoroutineLiveData.kt+function:liveData) Added in [2.7.0](https://developer.android.com/jetpack/androidx/releases/lifecycle#2.7.0)

```
@RequiresApi(value = 26)
fun <T : Any?> liveData(
    timeout: Duration,
    context: CoroutineContext = EmptyCoroutineContext,
    block: suspend LiveDataScope<T>.() -> Unit
): LiveData<T>
```

Builds a LiveData that has values yielded from the given `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#liveData(java.time.Duration,kotlin.coroutines.CoroutineContext,kotlin.coroutines.SuspendFunction1)` that executes on a `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveDataScope`.

The `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#liveData(java.time.Duration,kotlin.coroutines.CoroutineContext,kotlin.coroutines.SuspendFunction1)` starts executing when the returned `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData` becomes LiveData.onActive. If the `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData` becomes LiveData.onInactive while the `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#liveData(java.time.Duration,kotlin.coroutines.CoroutineContext,kotlin.coroutines.SuspendFunction1)` is executing, it will be cancelled after the `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#liveData(java.time.Duration,kotlin.coroutines.CoroutineContext,kotlin.coroutines.SuspendFunction1)` duration unless the `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData` becomes active again before that timeout (to gracefully handle cases like Activity rotation). Any value `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveDataScope#emit(kotlin.Any)`ed from a cancelled `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#liveData(java.time.Duration,kotlin.coroutines.CoroutineContext,kotlin.coroutines.SuspendFunction1)` will be ignored.

After a cancellation, if the `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData` becomes active again, the `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#liveData(java.time.Duration,kotlin.coroutines.CoroutineContext,kotlin.coroutines.SuspendFunction1)` will be re-executed from the beginning. If you would like to continue the operations based on where it was stopped last, you can use the `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveDataScope#latestValue()` function to get the last `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveDataScope#emit(kotlin.Any)`ed value.

If the `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#liveData(java.time.Duration,kotlin.coroutines.CoroutineContext,kotlin.coroutines.SuspendFunction1)` completes successfully *or* is cancelled due to reasons other than `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData` becoming inactive, it *will not* be re-executed even after `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData` goes through active inactive cycle.

As a best practice, it is important for the `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#liveData(java.time.Duration,kotlin.coroutines.CoroutineContext,kotlin.coroutines.SuspendFunction1)` to cooperate in cancellation. See kotlin coroutines documentation for details https://kotlinlang.org/docs/reference/coroutines/cancellation-and-timeouts.html.

The `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#liveData(java.time.Duration,kotlin.coroutines.CoroutineContext,kotlin.coroutines.SuspendFunction1)` can be changed to fit different use cases better, for example increasing it will give more time to the `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#liveData(java.time.Duration,kotlin.coroutines.CoroutineContext,kotlin.coroutines.SuspendFunction1)` to complete even if `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData` is inactive. It is good for cases when `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#liveData(java.time.Duration,kotlin.coroutines.CoroutineContext,kotlin.coroutines.SuspendFunction1)` is finite (meaning it can complete successfully) and is costly to restart. Otherwise if a `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#liveData(java.time.Duration,kotlin.coroutines.CoroutineContext,kotlin.coroutines.SuspendFunction1)` is cheap to restart, decreasing the `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#liveData(java.time.Duration,kotlin.coroutines.CoroutineContext,kotlin.coroutines.SuspendFunction1)` value will allow to yield less values that aren't consumed by anything.

```kotlin
// a simple LiveData that receives value 3, 3 seconds after being observed for the first time.
val data : LiveData<Int> = liveData {
    delay(3000)
    emit(3)
}


// a LiveData that fetches a `User` object based on a `userId` and refreshes it every 30 seconds
// as long as it is observed
val userId : LiveData<String> = ...
val user = userId.switchMap { id ->
    liveData {
      while(true) {
        // note that `while(true)` is fine because the `delay(30_000)` below will cooperate in
        // cancellation if LiveData is not actively observed anymore
        val data = api.fetch(id) // errors are ignored for brevity
        emit(data)
        delay(30_000)
      }
    }
}

// A retrying data fetcher with doubling back-off
val user = liveData {
    var backOffTime = 1_000
    var succeeded = false
    while(!succeeded) {
        try {
            emit(api.fetch(id))
            succeeded = true
        } catch(ioError : IOException) {
            delay(backOffTime)
            backOffTime *= minOf(backOffTime * 2, 60_000)
        }
    }
}

// a LiveData that tries to load the `User` from local cache first and then tries to fetch
// from the server and also yields the updated value
val user = liveData {
    // dispatch loading first
    emit(LOADING(id))
    // check local storage
    val cached = cache.loadUser(id)
    if (cached != null) {
        emit(cached)
    }
    if (cached == null || cached.isStale()) {
        val fresh = api.fetch(id) // errors are ignored for brevity
        cache.save(fresh)
        emit(fresh)
    }
}

// a LiveData that immediately receives a LiveData<User> from the database and yields it as a
// source but also tries to back-fill the database from the server
val user = liveData {
    val fromDb: LiveData<User> = roomDatabase.loadUser(id)
    emitSource(fromDb)
    val updated = api.fetch(id) // errors are ignored for brevity
    // Since we are using Room here, updating the database will update the `fromDb` LiveData
    // that was obtained above. See Room's documentation for more details.
    // https://developer.android.com/training/data-storage/room/accessing-data#query-observable
    roomDatabase.insert(updated)
}
```

| Parameters |
|---|---|
| `timeout: https://developer.android.com/reference/java/time/Duration.html` | The timeout duration before cancelling the block if there are no active observers (`https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData#hasActiveObservers()`. |
| `context: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-coroutine-context/index.html = EmptyCoroutineContext` | The CoroutineContext to run the given block in. Defaults to `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-empty-coroutine-context/index.html` combined with `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-main-coroutine-dispatcher/immediate.html`. |
| `block: suspend https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveDataScope<T>.() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | The block to run when the `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData` has active observers. |

### toPublisher

android Artifact: [androidx.lifecycle:lifecycle-reactivestreams](https://developer.android.com/jetpack/androidx/releases/lifecycle) [View Source](https://cs.android.com/search?q=file:androidx/lifecycle/LiveDataReactiveStreams.kt+function:toPublisher) Added in [2.0.0](https://developer.android.com/jetpack/androidx/releases/lifecycle#2.0.0) Deprecated in [2.8.0](https://developer.android.com/jetpack/androidx/releases/lifecycle#2.8.0)

```
fun <T : Any?> [toPublisher](https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#toPublisher(androidx.lifecycle.LifecycleOwner,androidx.lifecycle.LiveData))(lifecycle: LifecycleOwner, liveData: LiveData<T>): Publisher<T>
```

> [!CAUTION]
> **This function is deprecated.**   
> Use the extension method \`liveData.toPublisher(lifecycleOwner)\` instead, use this instead:
>
> ```kotlin
> liveData.toPublisher(lifecycleOwner)
> ```

Adapts the given `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData` stream to a ReactiveStreams `https://www.reactive-streams.org/reactive-streams-1.0.4-javadoc/org/reactivestreams/Publisher.html`.

By using a good publisher implementation such as RxJava 2.x Flowables, most consumers will be able to let the library deal with backpressure using operators and not need to worry about ever manually calling `https://www.reactive-streams.org/reactive-streams-1.0.4-javadoc/org/reactivestreams/Subscription.html#request(long)`.

On subscription to the publisher, the observer will attach to the given `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData`. Once `https://www.reactive-streams.org/reactive-streams-1.0.4-javadoc/org/reactivestreams/Subscription.html#request(long)` is called on the subscription object, an observer will be connected to the data stream. Calling `request(Long.MAX_VALUE)` is equivalent to creating an unbounded stream with no backpressure. If request with a finite count reaches 0, the observer will buffer the latest item and emit it to the subscriber when data is again requested. Any other items emitted during the time there was no backpressure requested will be dropped.

## Extension functions

### Lifecycle.addObserver

Cmn 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.kt+function:addObserver) Added in [2.11.0](https://developer.android.com/jetpack/androidx/releases/lifecycle#2.11.0)

```
inline fun Lifecycle.addObserver(
    crossinline action: LifecycleObserver.(source: LifecycleOwner, event: Lifecycle.Event) -> Unit
): LifecycleObserver
```

Adds a `https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleObserver` to this `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle` using the provided `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.Lifecycle).addObserver(kotlin.Function3)`.

Invokes `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.Lifecycle).addObserver(kotlin.Function3)` whenever a `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.Event` occurs.

| Parameters |
|---|---|
| `crossinline action: https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleObserver.(source: https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleOwner, event: https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.Event) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | The action invoked on each `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.Event`, providing the `https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleOwner` and the specific `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.Event`. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleObserver` | the added `https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleObserver` instance (can be used to later remove it). |

### LiveData.asFlow

android Artifact: [androidx.lifecycle:lifecycle-livedata](https://developer.android.com/jetpack/androidx/releases/lifecycle) [View Source](https://cs.android.com/search?q=file:androidx/lifecycle/FlowLiveData.kt+function:asFlow) Added in [2.7.0](https://developer.android.com/jetpack/androidx/releases/lifecycle#2.7.0)

```
fun <T : Any?> LiveData<T>.asFlow(): Flow<T>
```

Creates a `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html` containing values dispatched by originating `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData`: at the start a flow collector receives the latest value held by LiveData and then observes LiveData updates.

When a collection of the returned flow starts the originating `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData` becomes `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData#onActive()`. Similarly, when a collection completes `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData` becomes `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData#onInactive()`.

BackPressure: the returned flow is conflated. There is no mechanism to suspend an emission by LiveData due to a slow collector, so collector always gets the most recent value emitted.

### Flow.asLiveData

android Artifact: [androidx.lifecycle:lifecycle-livedata](https://developer.android.com/jetpack/androidx/releases/lifecycle) [View Source](https://cs.android.com/search?q=file:androidx/lifecycle/FlowLiveData.kt+function:asLiveData)

```
fun <T : Any?> Flow<T>.asLiveData(
    context: CoroutineContext = EmptyCoroutineContext,
    timeoutInMs: Long = DEFAULT_TIMEOUT
): LiveData<T>
```

Creates a LiveData that has values collected from the origin `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html`.

If the origin `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html` is a `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-state-flow/index.html`, then the initial value will be populated to the `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData`'s value field on the main thread.

The upstream flow collection starts when the returned `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData` becomes active (`https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData#onActive()`). If the `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData` becomes inactive (`https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData#onInactive()`) while the flow has not completed, the flow collection will be cancelled after `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(kotlinx.coroutines.flow.Flow).asLiveData(kotlin.coroutines.CoroutineContext,kotlin.Long)` milliseconds unless the `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData` becomes active again before that timeout (to gracefully handle cases like Activity rotation).

After a cancellation, if the `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData` becomes active again, the upstream flow collection will be re-executed.

If the upstream flow completes successfully *or* is cancelled due to reasons other than `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData` becoming inactive, it *will not* be re-collected even after `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData` goes through active inactive cycle.

If flow completes with an exception, then exception will be delivered to the `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-exception-handler/index.html` of provided `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(kotlinx.coroutines.flow.Flow).asLiveData(kotlin.coroutines.CoroutineContext,kotlin.Long)`. By default `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-empty-coroutine-context/index.html` is used to so an exception will be delivered to main's thread `https://developer.android.com/reference/java/lang/Thread.UncaughtExceptionHandler.html`. If your flow upstream is expected to throw, you can use `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/index.html` on upstream flow to emit a helpful error object.

The `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(kotlinx.coroutines.flow.Flow).asLiveData(kotlin.coroutines.CoroutineContext,kotlin.Long)` can be changed to fit different use cases better, for example increasing it will give more time to flow to complete before being canceled and is good for finite flows that are costly to restart. Otherwise if a flow is cheap to restart decreasing the `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(kotlinx.coroutines.flow.Flow).asLiveData(kotlin.coroutines.CoroutineContext,kotlin.Long)` value will allow to produce less values that aren't consumed by anything.

| Parameters |
|---|---|
| `context: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-coroutine-context/index.html = EmptyCoroutineContext` | The CoroutineContext to collect the upstream flow in. Defaults to `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-empty-coroutine-context/index.html` combined with `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-main-coroutine-dispatcher/immediate.html` |
| `timeoutInMs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html = DEFAULT_TIMEOUT` | The timeout in ms before cancelling the block if there are no active observers (`https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData#hasActiveObservers()`. Defaults to `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#DEFAULT_TIMEOUT()`. |

### Flow.asLiveData

android Artifact: [androidx.lifecycle:lifecycle-livedata](https://developer.android.com/jetpack/androidx/releases/lifecycle) [View Source](https://cs.android.com/search?q=file:androidx/lifecycle/FlowLiveData.kt+function:asLiveData)

```
@RequiresApi(value = 26)
fun <T : Any?> Flow<T>.asLiveData(
    timeout: Duration,
    context: CoroutineContext = EmptyCoroutineContext
): LiveData<T>
```

Creates a LiveData that has values collected from the origin `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html`.

The upstream flow collection starts when the returned `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData` becomes active (`https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData#onActive()`). If the `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData` becomes inactive (`https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData#onInactive()`) while the flow has not completed, the flow collection will be cancelled after `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(kotlinx.coroutines.flow.Flow).asLiveData(java.time.Duration,kotlin.coroutines.CoroutineContext)` unless the `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData` becomes active again before that timeout (to gracefully handle cases like Activity rotation).

After a cancellation, if the `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData` becomes active again, the upstream flow collection will be re-executed.

If the upstream flow completes successfully *or* is cancelled due to reasons other than `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData` becoming inactive, it *will not* be re-collected even after `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData` goes through active inactive cycle.

If flow completes with an exception, then exception will be delivered to the `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-exception-handler/index.html` of provided `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(kotlinx.coroutines.flow.Flow).asLiveData(java.time.Duration,kotlin.coroutines.CoroutineContext)`. By default `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-empty-coroutine-context/index.html` is used to so an exception will be delivered to main's thread `https://developer.android.com/reference/java/lang/Thread.UncaughtExceptionHandler.html`. If your flow upstream is expected to throw, you can use `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/index.html` on upstream flow to emit a helpful error object.

The `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(kotlinx.coroutines.flow.Flow).asLiveData(java.time.Duration,kotlin.coroutines.CoroutineContext)` can be changed to fit different use cases better, for example increasing it will give more time to flow to complete before being canceled and is good for finite flows that are costly to restart. Otherwise if a flow is cheap to restart decreasing the `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(kotlinx.coroutines.flow.Flow).asLiveData(java.time.Duration,kotlin.coroutines.CoroutineContext)` value will allow to produce less values that aren't consumed by anything.

| Parameters |
|---|---|
| `timeout: https://developer.android.com/reference/java/time/Duration.html` | The timeout in ms before cancelling the block if there are no active observers (`https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData#hasActiveObservers()`. Defaults to `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#DEFAULT_TIMEOUT()`. |
| `context: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-coroutine-context/index.html = EmptyCoroutineContext` | The CoroutineContext to collect the upstream flow in. Defaults to `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-empty-coroutine-context/index.html` combined with `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-main-coroutine-dispatcher/immediate.html` |

### CreationExtras.createSavedStateHandle

Cmn Artifact: [androidx.lifecycle:lifecycle-viewmodel-savedstate](https://developer.android.com/jetpack/androidx/releases/lifecycle) [View Source](https://cs.android.com/search?q=file:androidx/lifecycle/SavedStateHandleSupport.kt+function:createSavedStateHandle) Added in [2.5.0](https://developer.android.com/jetpack/androidx/releases/lifecycle#2.5.0)

```
@MainThread
fun CreationExtras.createSavedStateHandle(): SavedStateHandle
```

Creates a `https://developer.android.com/reference/kotlin/androidx/lifecycle/SavedStateHandle` for use in your `https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModel`s.

This function requires a call to `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.savedstate.SavedStateRegistryOwner).enableSavedStateHandles()` during component initialization. Modern Jetpack components (such as `ComponentActivity`, `Fragment`, and `NavBackStackEntry`) perform this call automatically.

The `https://developer.android.com/reference/kotlin/androidx/lifecycle/viewmodel/CreationExtras` must contain `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#SAVED_STATE_REGISTRY_OWNER_KEY()`, `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#VIEW_MODEL_STORE_OWNER_KEY()`, and `https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModelProvider#VIEW_MODEL_KEY()`.

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/lifecycle/SavedStateHandle` | new `https://developer.android.com/reference/kotlin/androidx/lifecycle/SavedStateHandle` instance |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html` | If the `https://developer.android.com/reference/kotlin/androidx/lifecycle/viewmodel/CreationExtras` is missing any of the required keys: `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#VIEW_MODEL_STORE_OWNER_KEY()`, `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#SAVED_STATE_REGISTRY_OWNER_KEY()`, or `https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModelProvider#VIEW_MODEL_KEY()`. |

### LiveData.distinctUntilChanged

android Artifact: [androidx.lifecycle:lifecycle-livedata](https://developer.android.com/jetpack/androidx/releases/lifecycle) [View Source](https://cs.android.com/search?q=file:androidx/lifecycle/Transformations.kt+function:distinctUntilChanged) Added in [2.1.0](https://developer.android.com/jetpack/androidx/releases/lifecycle#2.1.0)

```
@MainThread
fun <X : Any?> LiveData<X>.distinctUntilChanged(): LiveData<X>
```

Creates a new `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData` object does not emit a value until the source `this` LiveData value has been changed. The value is considered changed if `equals()` yields `false`.

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData<X>` | a new `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData` of type `X` |

### T.enableSavedStateHandles

Cmn Artifact: [androidx.lifecycle:lifecycle-viewmodel-savedstate](https://developer.android.com/jetpack/androidx/releases/lifecycle) [View Source](https://cs.android.com/search?q=file:androidx/lifecycle/SavedStateHandleSupport.kt+function:enableSavedStateHandles) Added in [2.5.0](https://developer.android.com/jetpack/androidx/releases/lifecycle#2.5.0)

```
@MainThread
fun <T : SavedStateRegistryOwner & ViewModelStoreOwner> T.enableSavedStateHandles(

): Unit
```

Enables support for `https://developer.android.com/reference/kotlin/androidx/lifecycle/SavedStateHandle` in a component.

After calling this method, `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.viewmodel.CreationExtras).createSavedStateHandle()` can be invoked on `https://developer.android.com/reference/kotlin/androidx/lifecycle/viewmodel/CreationExtras` containing the `https://developer.android.com/reference/kotlin/androidx/savedstate/SavedStateRegistryOwner` and `https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModelStoreOwner`.

This must be called while the component is in the `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State#INITIALIZED` or `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State#CREATED` state, and before requesting any `https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModel` that requires a `https://developer.android.com/reference/kotlin/androidx/lifecycle/SavedStateHandle`.

### View.findViewTreeLifecycleOwner

android Artifact: [androidx.lifecycle:lifecycle-runtime](https://developer.android.com/jetpack/androidx/releases/lifecycle) [View Source](https://cs.android.com/search?q=file:androidx/lifecycle/ViewTreeLifecycleOwner.android.kt+function:findViewTreeLifecycleOwner) Added in [2.3.0](https://developer.android.com/jetpack/androidx/releases/lifecycle#2.3.0)

```
fun View.findViewTreeLifecycleOwner(): LifecycleOwner?
```

Retrieve the `https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleOwner` responsible for managing the given `https://developer.android.com/reference/android/view/View.html`. This may be used to scope work or heavyweight resources associated with the view that may span cycles of the view becoming detached and reattached from a window.

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleOwner?` | The `https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleOwner` responsible for managing this view and/or some subset of its ancestors |

### View.findViewTreeViewModelStoreOwner

android Artifact: [androidx.lifecycle:lifecycle-viewmodel](https://developer.android.com/jetpack/androidx/releases/lifecycle) [View Source](https://cs.android.com/search?q=file:androidx/lifecycle/ViewTreeViewModelStoreOwner.android.kt+function:findViewTreeViewModelStoreOwner) Added in [2.3.0](https://developer.android.com/jetpack/androidx/releases/lifecycle#2.3.0)

```
fun View.findViewTreeViewModelStoreOwner(): ViewModelStoreOwner?
```

Retrieves the `https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModelStoreOwner` associated with the given `https://developer.android.com/reference/android/view/View.html`.

Used to retain state associated with this view across configuration changes.

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModelStoreOwner?` | `https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModelStoreOwner` associated with this view or its ancestors |

### Flow.flowWithLifecycle

Cmn Artifact: [androidx.lifecycle:lifecycle-runtime](https://developer.android.com/jetpack/androidx/releases/lifecycle) [View Source](https://cs.android.com/search?q=file:androidx/lifecycle/FlowExt.kt+function:flowWithLifecycle)

```
fun <T : Any?> Flow<T>.flowWithLifecycle(
    lifecycle: Lifecycle,
    minActiveState: Lifecycle.State = Lifecycle.State.STARTED
): Flow<T>
```

Flow operator that emits values from `this` upstream Flow when the `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(kotlinx.coroutines.flow.Flow).flowWithLifecycle(androidx.lifecycle.Lifecycle,androidx.lifecycle.Lifecycle.State)` is at least at `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(kotlinx.coroutines.flow.Flow).flowWithLifecycle(androidx.lifecycle.Lifecycle,androidx.lifecycle.Lifecycle.State)` state. The emissions will be stopped when the lifecycle state falls below `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(kotlinx.coroutines.flow.Flow).flowWithLifecycle(androidx.lifecycle.Lifecycle,androidx.lifecycle.Lifecycle.State)` state.

The flow will automatically start and cancel collecting from `this` upstream flow as the `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(kotlinx.coroutines.flow.Flow).flowWithLifecycle(androidx.lifecycle.Lifecycle,androidx.lifecycle.Lifecycle.State)` moves in and out of the target state.

If `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html` upstream Flow completes emitting items, `flowWithLifecycle` will trigger the flow collection again when the `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(kotlinx.coroutines.flow.Flow).flowWithLifecycle(androidx.lifecycle.Lifecycle,androidx.lifecycle.Lifecycle.State)` state is reached.

This is NOT a terminal operator. This operator is usually followed by `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/collect.html`, or `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/index.html` and `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/index.html` to process the emitted values.

Note: this operator creates a hot flow that only closes when the `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(kotlinx.coroutines.flow.Flow).flowWithLifecycle(androidx.lifecycle.Lifecycle,androidx.lifecycle.Lifecycle.State)` is destroyed or the coroutine that collects from the flow is cancelled.

```kotlin
class MyActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        /* ... */
        // Launches a coroutine that collects items from a flow when the Activity
        // is at least started. It will automatically cancel when the activity is stopped and
        // start collecting again whenever it's started again.
        lifecycleScope.launch {
            flow
                .flowWithLifecycle(lifecycle, Lifecycle.State.STARTED)
                .collect {
                    // Consume flow emissions
                 }
        }
    }
}
```

`flowWithLifecycle` cancels the upstream Flow when `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(kotlinx.coroutines.flow.Flow).flowWithLifecycle(androidx.lifecycle.Lifecycle,androidx.lifecycle.Lifecycle.State)` falls below `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(kotlinx.coroutines.flow.Flow).flowWithLifecycle(androidx.lifecycle.Lifecycle,androidx.lifecycle.Lifecycle.State)` state. However, the downstream Flow will be active without receiving any emissions as long as the scope used to collect the Flow is active. As such, please take care when using this function in an operator chain, as the order of the operators matters. For example, `flow1.flowWithLifecycle(lifecycle).combine(flow2)` behaves differently than `flow1.combine(flow2).flowWithLifecycle(lifecycle)`. The former continues to combine both flows even when `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(kotlinx.coroutines.flow.Flow).flowWithLifecycle(androidx.lifecycle.Lifecycle,androidx.lifecycle.Lifecycle.State)` falls below `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(kotlinx.coroutines.flow.Flow).flowWithLifecycle(androidx.lifecycle.Lifecycle,androidx.lifecycle.Lifecycle.State)` state whereas the combination is cancelled in the latter case.

Warning: `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State#INITIALIZED` is not allowed in this API. Passing it as a parameter will throw an `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html`.

Tip: If multiple flows need to be collected using `flowWithLifecycle`, consider using the `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.Lifecycle).repeatOnLifecycle(androidx.lifecycle.Lifecycle.State,kotlin.coroutines.SuspendFunction1)` API to collect from all of them using a different `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/index.html` per flow instead. That's more efficient and consumes less resources as no hot flows are created.

| Parameters |
|---|---|
| `lifecycle: https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle` | The `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle` where the restarting collecting from `this` flow work will be kept alive. |
| `minActiveState: https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State = Lifecycle.State.STARTED` | `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State` in which the upstream flow gets collected. The collection will stop if the lifecycle falls below that state, and will restart if it's in that state again. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html<T>` | `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html` that only emits items from `this` upstream flow when the `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(kotlinx.coroutines.flow.Flow).flowWithLifecycle(androidx.lifecycle.Lifecycle,androidx.lifecycle.Lifecycle.State)` is at least in the `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(kotlinx.coroutines.flow.Flow).flowWithLifecycle(androidx.lifecycle.Lifecycle,androidx.lifecycle.Lifecycle.State)`. |

### ViewModelProvider.get

Cmn Artifact: [androidx.lifecycle:lifecycle-viewmodel](https://developer.android.com/jetpack/androidx/releases/lifecycle) [View Source](https://cs.android.com/search?q=file:androidx/lifecycle/ViewModelProviderGet.kt+function:get)

```
@MainThread
inline fun <VM : ViewModel> ViewModelProvider.get(): VM
```

Returns an existing ViewModel or creates a new one in the scope (usually, a fragment or an activity), associated with this `ViewModelProvider`.

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModelProvider#get(kotlin.reflect.KClass)` | (Class) |

### ViewModelProvider.get

Cmn Artifact: [androidx.lifecycle:lifecycle-viewmodel](https://developer.android.com/jetpack/androidx/releases/lifecycle) [View Source](https://cs.android.com/search?q=file:androidx/lifecycle/ViewModelProviderGet.kt+function:get)

```
@MainThread
inline fun <VM : ViewModel> ViewModelProvider.get(key: String): VM
```

Returns an existing ViewModel or creates a new one in the scope (usually, a fragment or an activity), associated with this `ViewModelProvider` and the given `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.ViewModelProvider).get(kotlin.String)`.

| Parameters |
|---|---|
| `key: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | The key to use to identify the ViewModel. |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModelProvider#get(kotlin.reflect.KClass)` | (String, Class) |

### LiveData.map

android Artifact: [androidx.lifecycle:lifecycle-livedata](https://developer.android.com/jetpack/androidx/releases/lifecycle) [View Source](https://cs.android.com/search?q=file:androidx/lifecycle/Transformations.kt+function:map)

```
@MainThread
fun <X : Any?, Y : Any?> LiveData<X>.map(transform: (X) -> Y): LiveData<Y>
```

Returns a `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData` mapped from `this` LiveData by applying `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.LiveData).map(kotlin.Function1)` to each value set on `this` LiveData.

This method is analogous to `https://reactivex.io/RxJava/2.x/javadoc/io/reactivex/Observable.html#map-io.reactivex.functions.Function&lt;? super T,? extends R&gt;-`.

`https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.LiveData).map(kotlin.Function1)` will be executed on the main thread.

Here is an example mapping a simple `User` struct in a `LiveData` to a `LiveData` containing their full name as a `String`.

```kotlin
val userLD : LiveData<User> = ...;
val userFullNameLD: LiveData<String> = userLD.map { user -> user.firstName + user.lastName }
```

| Parameters |
|---|---|
| `transform: (X) -> Y` | a function to apply to each value set on `source` in order to set it on the output `LiveData` |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData<Y>` | a LiveData mapped from `source` to type `<Y>` by applying `mapFunction` to each value set. |

### LiveData.observe

android Artifact: [androidx.lifecycle:lifecycle-livedata-core](https://developer.android.com/jetpack/androidx/releases/lifecycle) [View Source](https://cs.android.com/search?q=file:androidx/lifecycle/LiveData.kt+function:observe) Added in [2.8.0](https://developer.android.com/jetpack/androidx/releases/lifecycle#2.8.0) Deprecated in [2.8.0](https://developer.android.com/jetpack/androidx/releases/lifecycle#2.8.0)

```
@MainThread
inline fun <T : Any?> LiveData<T>.[observe](https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.LiveData).observe(androidx.lifecycle.LifecycleOwner,kotlin.Function1))(
    owner: LifecycleOwner,
    crossinline onChanged: (T) -> Unit
): Observer<T>
```

> [!CAUTION]
> **This function is deprecated.**   
> This extension method is not required when using Kotlin 1.4. You should remove "import androidx.lifecycle.observe"

Adds the given `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.LiveData).observe(androidx.lifecycle.LifecycleOwner,kotlin.Function1)` lambda as an observer within the lifespan of the given `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.LiveData).observe(androidx.lifecycle.LifecycleOwner,kotlin.Function1)` and returns a reference to observer. The events are dispatched on the main thread. If LiveData already has data set, it will be delivered to the onChanged.

The observer will only receive events if the owner is in `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State#STARTED` or `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State#RESUMED` state (active).

If the owner moves to the `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State#DESTROYED` state, the observer will automatically be removed.

When data changes while the `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.LiveData).observe(androidx.lifecycle.LifecycleOwner,kotlin.Function1)` is not active, it will not receive any updates. If it becomes active again, it will receive the last available data automatically.

LiveData keeps a strong reference to the observer and the owner as long as the given LifecycleOwner is not destroyed. When it is destroyed, LiveData removes references to the observer and the owner.

If the given owner is already in `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State#DESTROYED` state, LiveData ignores the call.

### Lifecycle.repeatOnLifecycle

Cmn Artifact: [androidx.lifecycle:lifecycle-runtime](https://developer.android.com/jetpack/androidx/releases/lifecycle) [View Source](https://cs.android.com/search?q=file:androidx/lifecycle/RepeatOnLifecycle.kt+function:repeatOnLifecycle) Added in [2.8.0](https://developer.android.com/jetpack/androidx/releases/lifecycle#2.8.0)

```
suspend fun Lifecycle.repeatOnLifecycle(
    state: Lifecycle.State,
    block: suspend CoroutineScope.() -> Unit
): Unit
```

Runs the given `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.Lifecycle).repeatOnLifecycle(androidx.lifecycle.Lifecycle.State,kotlin.coroutines.SuspendFunction1)` in a new coroutine when `this` `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle` is at least at `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.Lifecycle).repeatOnLifecycle(androidx.lifecycle.Lifecycle.State,kotlin.coroutines.SuspendFunction1)` and suspends the execution until `this` `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle` is `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State#DESTROYED`.

The `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.Lifecycle).repeatOnLifecycle(androidx.lifecycle.Lifecycle.State,kotlin.coroutines.SuspendFunction1)` will cancel and re-launch as the lifecycle moves in and out of the target state.

```kotlin
class MyActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        /* ... */
        // Runs the block of code in a coroutine when the lifecycle is at least STARTED.
        // The coroutine will be cancelled when the ON_STOP event happens and will
        // restart executing if the lifecycle receives the ON_START event again.
        lifecycleScope.launch {
            lifecycle.repeatOnLifecycle(Lifecycle.State.STARTED) {
                uiStateFlow.collect { uiState ->
                    updateUi(uiState)
                }
            }
        }
    }
}
```

The best practice is to call this function when the lifecycle is initialized. For example, `onCreate` in an Activity, or `onViewCreated` in a Fragment. Otherwise, multiple repeating coroutines doing the same could be created and be executed at the same time.

Repeated invocations of `block` will run serially, that is they will always wait for the previous invocation to fully finish before re-starting execution as the state moves in and out of the required state.

**Thread Safety** : This function always executes the lifecycle registration and synchronization on `Dispatchers.Main.immediate`. If the caller coroutine context runs on a different dispatcher, it yields to the main dispatcher. The target `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.Lifecycle).repeatOnLifecycle(androidx.lifecycle.Lifecycle.State,kotlin.coroutines.SuspendFunction1)` also executes on the main dispatcher.

**Warning:** `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State#INITIALIZED` is not allowed in this API. Passing it as a parameter will throw an `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html`.

| Parameters |
|---|---|
| `state: https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State` | `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State` in which `block` runs in a new coroutine. That coroutine will cancel if the lifecycle falls below that state, and will restart if it's in that state again. |
| `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` | The block to run when the lifecycle is at least in `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.Lifecycle).repeatOnLifecycle(androidx.lifecycle.Lifecycle.State,kotlin.coroutines.SuspendFunction1)` state. |

### LifecycleOwner.repeatOnLifecycle

Cmn Artifact: [androidx.lifecycle:lifecycle-runtime](https://developer.android.com/jetpack/androidx/releases/lifecycle) [View Source](https://cs.android.com/search?q=file:androidx/lifecycle/RepeatOnLifecycle.kt+function:repeatOnLifecycle) Added in [2.8.0](https://developer.android.com/jetpack/androidx/releases/lifecycle#2.8.0)

```
suspend fun LifecycleOwner.repeatOnLifecycle(
    state: Lifecycle.State,
    block: suspend CoroutineScope.() -> Unit
): Unit
```

`https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleOwner`'s extension function for `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.Lifecycle).repeatOnLifecycle(androidx.lifecycle.Lifecycle.State,kotlin.coroutines.SuspendFunction1)` to allow an easier call to the API from LifecycleOwners such as Activities and Fragments.

```kotlin
class MyActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        /* ... */
        // Runs the block of code in a coroutine when the lifecycle is at least STARTED.
        // The coroutine will be cancelled when the ON_STOP event happens and will
        // restart executing if the lifecycle receives the ON_START event again.
        lifecycleScope.launch {
            repeatOnLifecycle(Lifecycle.State.STARTED) {
                uiStateFlow.collect { uiState ->
                    updateUi(uiState)
                }
            }
        }
    }
}
```

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

### View.setViewTreeLifecycleOwner

android Artifact: [androidx.lifecycle:lifecycle-runtime](https://developer.android.com/jetpack/androidx/releases/lifecycle) [View Source](https://cs.android.com/search?q=file:androidx/lifecycle/ViewTreeLifecycleOwner.android.kt+function:setViewTreeLifecycleOwner) Added in [2.3.0](https://developer.android.com/jetpack/androidx/releases/lifecycle#2.3.0)

```
fun View.setViewTreeLifecycleOwner(lifecycleOwner: LifecycleOwner?): Unit
```

Set the `https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleOwner` responsible for managing the given `https://developer.android.com/reference/android/view/View.html`. Calls to `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.ViewModelProvider).get()` from this view or descendants will return `lifecycleOwner`.

This should only be called by constructs such as activities or fragments that manage a view tree and reflect their own lifecycle through a `https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleOwner`. Callers should only set a `https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleOwner` that will be *stable.* The associated lifecycle should report that it is destroyed if the view tree is removed and is not guaranteed to later become reattached to a window.

| Parameters |
|---|---|
| `lifecycleOwner: https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleOwner?` | LifecycleOwner representing the manager of the given view |

### View.setViewTreeViewModelStoreOwner

android Artifact: [androidx.lifecycle:lifecycle-viewmodel](https://developer.android.com/jetpack/androidx/releases/lifecycle) [View Source](https://cs.android.com/search?q=file:androidx/lifecycle/ViewTreeViewModelStoreOwner.android.kt+function:setViewTreeViewModelStoreOwner) Added in [2.3.0](https://developer.android.com/jetpack/androidx/releases/lifecycle#2.3.0)

```
fun View.setViewTreeViewModelStoreOwner(
    viewModelStoreOwner: ViewModelStoreOwner?
): Unit
```

Sets the `https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModelStoreOwner` associated with the given `https://developer.android.com/reference/android/view/View.html`.

Calls to `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(android.view.View).findViewTreeViewModelStoreOwner()` from this view or its descendants will return `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(android.view.View).setViewTreeViewModelStoreOwner(androidx.lifecycle.ViewModelStoreOwner)`.

This should only be called by constructs such as `Activity`s or `Fragment`s that manage a view tree and retain state through a `https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModelStoreOwner`. Callers should only set a `https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModelStoreOwner` that is stable. The associated `https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModelStore` should be cleared if the view tree is removed and is not guaranteed to later become reattached to a window.

| Parameters |
|---|---|
| `viewModelStoreOwner: https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModelStoreOwner?` | `https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModelStoreOwner` to associate with this `https://developer.android.com/reference/android/view/View.html` |

### LiveData.switchMap

android Artifact: [androidx.lifecycle:lifecycle-livedata](https://developer.android.com/jetpack/androidx/releases/lifecycle) [View Source](https://cs.android.com/search?q=file:androidx/lifecycle/Transformations.kt+function:switchMap)

```
@MainThread
fun <X : Any?, Y : Any?> LiveData<X>.switchMap(transform: (X) -> LiveData<Y>?): LiveData<Y>
```

Returns a `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData` mapped from the input `this` `LiveData` by applying `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.LiveData).switchMap(kotlin.Function1)` to each value set on `this`.


The returned \`LiveData\` delegates to the most recent \`LiveData\` created by \[transform\] with the
most recent value set to \`this\`, without changing the reference. In this way \[transform\] can
change the 'backing' \`LiveData\` transparently to any observer registered to the \`LiveData\`
returned by \`switchMap()\`.

Note that when the backing `LiveData` is switched, no further values from the older `LiveData` will be set to the output `LiveData`. In this way, the method is analogous to `https://reactivex.io/RxJava/2.x/javadoc/io/reactivex/Observable.html#switchMap-io.reactivex.functions.Function&lt;? super T,? extends io.reactivex.ObservableSource&lt;? extends R&gt;&gt;-`.

`https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.LiveData).switchMap(kotlin.Function1)` will be executed on the main thread.

Here is an example class that holds a typed-in name of a user `String` (such as from an `EditText`) in a `https://developer.android.com/reference/kotlin/androidx/lifecycle/MutableLiveData` and returns a `LiveData` containing a List of `User` objects for users that have that name. It populates that `LiveData` by requerying a repository-pattern object each time the typed name changes.


This \`ViewModel\` would permit the observing UI to update "live" as the user ID text changes.

```kotlin
class UserViewModel: AndroidViewModel {
    val nameQueryLiveData : MutableLiveData<String> = ...

    fun usersWithNameLiveData(): LiveData<List<String>> = nameQueryLiveData.switchMap {
        name -> myDataSource.usersWithNameLiveData(name)
    }

    fun setNameQuery(val name: String) {
        this.nameQueryLiveData.value = name;
    }
}
```

| Parameters |
|---|---|
| `transform: (X) -> https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData<Y>?` | a function to apply to each value set on `source` to create a new delegate `LiveData` for the returned one |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData<Y>` | a LiveData mapped from `source` to type `<Y>` by delegating to the LiveData returned by applying `switchMapFunction` to each value set |

### Publisher.toLiveData

android Artifact: [androidx.lifecycle:lifecycle-reactivestreams](https://developer.android.com/jetpack/androidx/releases/lifecycle) [View Source](https://cs.android.com/search?q=file:androidx/lifecycle/LiveDataReactiveStreams.kt+function:toLiveData) Added in [2.0.0](https://developer.android.com/jetpack/androidx/releases/lifecycle#2.0.0)

```
fun <T : Any?> Publisher<T>.toLiveData(): LiveData<T>
```

Creates an observable `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData` stream from a ReactiveStreams `https://www.reactive-streams.org/reactive-streams-1.0.4-javadoc/org/reactivestreams/Publisher.html`}.

When the LiveData becomes active, it subscribes to the emissions from the Publisher.

When the LiveData becomes inactive, the subscription is cleared. LiveData holds the last value emitted by the Publisher when the LiveData was active.

Therefore, in the case of a hot RxJava Observable, when a new LiveData `https://developer.android.com/reference/kotlin/androidx/lifecycle/Observer` is added, it will automatically notify with the last value held in LiveData, which might not be the last value emitted by the Publisher.

Note that LiveData does NOT handle errors and it expects that errors are treated as states in the data that's held. In case of an error being emitted by the publisher, an error will be propagated to the main thread and the app will crash.

### LiveData.toPublisher

android Artifact: [androidx.lifecycle:lifecycle-reactivestreams](https://developer.android.com/jetpack/androidx/releases/lifecycle) [View Source](https://cs.android.com/search?q=file:androidx/lifecycle/LiveDataReactiveStreams.kt+function:toPublisher) Added in [2.6.0](https://developer.android.com/jetpack/androidx/releases/lifecycle#2.6.0)

```
fun <T : Any?> LiveData<T>.toPublisher(lifecycle: LifecycleOwner): Publisher<T>
```

Adapts the given `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData` stream to a ReactiveStreams `https://www.reactive-streams.org/reactive-streams-1.0.4-javadoc/org/reactivestreams/Publisher.html`.

By using a good publisher implementation such as RxJava 2.x Flowables, most consumers will be able to let the library deal with backpressure using operators and not need to worry about ever manually calling `https://www.reactive-streams.org/reactive-streams-1.0.4-javadoc/org/reactivestreams/Subscription.html#request(long)`.

On subscription to the publisher, the observer will attach to the given `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData`. Once `https://www.reactive-streams.org/reactive-streams-1.0.4-javadoc/org/reactivestreams/Subscription.html#request(long)` is called on the subscription object, an observer will be connected to the data stream. Calling `request(Long.MAX_VALUE)` is equivalent to creating an unbounded stream with no backpressure. If request with a finite count reaches 0, the observer will buffer the latest item and emit it to the subscriber when data is again requested. Any other items emitted during the time there was no backpressure requested will be dropped.

### LifecycleOwner.whenCreated

android Artifact: [androidx.lifecycle:lifecycle-common](https://developer.android.com/jetpack/androidx/releases/lifecycle) [View Source](https://cs.android.com/search?q=file:androidx/lifecycle/PausingDispatcher.jvm.kt+function:whenCreated)

```
suspend fun <T : Any?> LifecycleOwner.[whenCreated](https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.LifecycleOwner).whenCreated(kotlin.coroutines.SuspendFunction1))(block: suspend CoroutineScope.() -> T): T
```

> [!CAUTION]
> **This function is deprecated.**   
> whenCreated has been deprecated because it runs the block on a pausing dispatcher that suspends, rather than cancels work when the lifecycle state goes below the given state. Use withCreated for non-suspending work that needs to run only once when the Lifecycle changes.

Runs the given block when the `https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleOwner`'s `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle` is at least in `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State#CREATED` state.

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.Lifecycle).whenStateAtLeast(androidx.lifecycle.Lifecycle.State,kotlin.coroutines.SuspendFunction1)` | for details |

### Lifecycle.whenCreated

android Artifact: [androidx.lifecycle:lifecycle-common](https://developer.android.com/jetpack/androidx/releases/lifecycle) [View Source](https://cs.android.com/search?q=file:androidx/lifecycle/PausingDispatcher.jvm.kt+function:whenCreated)

```
suspend fun <T : Any?> Lifecycle.[whenCreated](https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.Lifecycle).whenCreated(kotlin.coroutines.SuspendFunction1))(block: suspend CoroutineScope.() -> T): T
```

> [!CAUTION]
> **This function is deprecated.**   
> whenCreated has been deprecated because it runs the block on a pausing dispatcher that suspends, rather than cancels work when the lifecycle state goes below the given state. Use withCreated for non-suspending work that needs to run only once when the Lifecycle changes.

Runs the given block when the `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle` is at least in `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State#CREATED` state.

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.Lifecycle).whenStateAtLeast(androidx.lifecycle.Lifecycle.State,kotlin.coroutines.SuspendFunction1)` | for details |

### LifecycleOwner.whenResumed

android Artifact: [androidx.lifecycle:lifecycle-common](https://developer.android.com/jetpack/androidx/releases/lifecycle) [View Source](https://cs.android.com/search?q=file:androidx/lifecycle/PausingDispatcher.jvm.kt+function:whenResumed)

```
suspend fun <T : Any?> LifecycleOwner.[whenResumed](https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.LifecycleOwner).whenResumed(kotlin.coroutines.SuspendFunction1))(block: suspend CoroutineScope.() -> T): T
```

> [!CAUTION]
> **This function is deprecated.**   
> whenResumed has been deprecated because it runs the block on a pausing dispatcher that suspends, rather than cancels work when the lifecycle state goes below the given state. Use withResumed for non-suspending work that needs to run only once when the Lifecycle changes.

Runs the given block when the `https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleOwner`'s `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle` is at least in `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State#RESUMED` state.

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.Lifecycle).whenStateAtLeast(androidx.lifecycle.Lifecycle.State,kotlin.coroutines.SuspendFunction1)` | for details |

### Lifecycle.whenResumed

android Artifact: [androidx.lifecycle:lifecycle-common](https://developer.android.com/jetpack/androidx/releases/lifecycle) [View Source](https://cs.android.com/search?q=file:androidx/lifecycle/PausingDispatcher.jvm.kt+function:whenResumed)

```
suspend fun <T : Any?> Lifecycle.[whenResumed](https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.Lifecycle).whenResumed(kotlin.coroutines.SuspendFunction1))(block: suspend CoroutineScope.() -> T): T
```

> [!CAUTION]
> **This function is deprecated.**   
> whenResumed has been deprecated because it runs the block on a pausing dispatcher that suspends, rather than cancels work when the lifecycle state goes below the given state. Use withResumed for non-suspending work that needs to run only once when the Lifecycle changes.

Runs the given block when the `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle` is at least in `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State#RESUMED` state.

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.Lifecycle).whenStateAtLeast(androidx.lifecycle.Lifecycle.State,kotlin.coroutines.SuspendFunction1)` | for details |

### LifecycleOwner.whenStarted

android Artifact: [androidx.lifecycle:lifecycle-common](https://developer.android.com/jetpack/androidx/releases/lifecycle) [View Source](https://cs.android.com/search?q=file:androidx/lifecycle/PausingDispatcher.jvm.kt+function:whenStarted)

```
suspend fun <T : Any?> LifecycleOwner.[whenStarted](https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.LifecycleOwner).whenStarted(kotlin.coroutines.SuspendFunction1))(block: suspend CoroutineScope.() -> T): T
```

> [!CAUTION]
> **This function is deprecated.**   
> whenStarted has been deprecated because it runs the block on a pausing dispatcher that suspends, rather than cancels work when the lifecycle state goes below the given state. Use withStarted for non-suspending work that needs to run only once when the Lifecycle changes.

Runs the given block when the `https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleOwner`'s `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle` is at least in `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State#STARTED` state.

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.Lifecycle).whenStateAtLeast(androidx.lifecycle.Lifecycle.State,kotlin.coroutines.SuspendFunction1)` | for details |

### Lifecycle.whenStarted

android Artifact: [androidx.lifecycle:lifecycle-common](https://developer.android.com/jetpack/androidx/releases/lifecycle) [View Source](https://cs.android.com/search?q=file:androidx/lifecycle/PausingDispatcher.jvm.kt+function:whenStarted)

```
suspend fun <T : Any?> Lifecycle.[whenStarted](https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.Lifecycle).whenStarted(kotlin.coroutines.SuspendFunction1))(block: suspend CoroutineScope.() -> T): T
```

> [!CAUTION]
> **This function is deprecated.**   
> whenStarted has been deprecated because it runs the block on a pausing dispatcher that suspends, rather than cancels work when the lifecycle state goes below the given state. Use withStarted for non-suspending work that needs to run only once when the Lifecycle changes.

Runs the given block when the `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle` is at least in `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State#STARTED` state.

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.Lifecycle).whenStateAtLeast(androidx.lifecycle.Lifecycle.State,kotlin.coroutines.SuspendFunction1)` | for details |

### Lifecycle.whenStateAtLeast

android Artifact: [androidx.lifecycle:lifecycle-common](https://developer.android.com/jetpack/androidx/releases/lifecycle) [View Source](https://cs.android.com/search?q=file:androidx/lifecycle/PausingDispatcher.jvm.kt+function:whenStateAtLeast)

```
suspend fun <T : Any?> Lifecycle.[whenStateAtLeast](https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.Lifecycle).whenStateAtLeast(androidx.lifecycle.Lifecycle.State,kotlin.coroutines.SuspendFunction1))(
    minState: Lifecycle.State,
    block: suspend CoroutineScope.() -> T
): T
```

> [!CAUTION]
> **This function is deprecated.**   
> whenStateAtLeast has been deprecated because it runs the block on a pausing dispatcher that suspends, rather than cancels work when the lifecycle state goes below the given state. Use withStateAtLeast for non-suspending work that needs to run only once when the Lifecycle changes.

Runs the given `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.Lifecycle).whenStateAtLeast(androidx.lifecycle.Lifecycle.State,kotlin.coroutines.SuspendFunction1)` on a `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-dispatcher/index.html` that executes the `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.Lifecycle).whenStateAtLeast(androidx.lifecycle.Lifecycle.State,kotlin.coroutines.SuspendFunction1)` on the main thread and suspends the execution unless the `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle`'s state is at least `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.Lifecycle).whenStateAtLeast(androidx.lifecycle.Lifecycle.State,kotlin.coroutines.SuspendFunction1)`.

If the `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle` moves to a lesser state while the `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.Lifecycle).whenStateAtLeast(androidx.lifecycle.Lifecycle.State,kotlin.coroutines.SuspendFunction1)` is running, the `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.Lifecycle).whenStateAtLeast(androidx.lifecycle.Lifecycle.State,kotlin.coroutines.SuspendFunction1)` will be suspended until the `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle` reaches to a state greater or equal to `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.Lifecycle).whenStateAtLeast(androidx.lifecycle.Lifecycle.State,kotlin.coroutines.SuspendFunction1)`.

Note that this won't effect any sub coroutine if they use a different `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-dispatcher/index.html`. However, the `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.Lifecycle).whenStateAtLeast(androidx.lifecycle.Lifecycle.State,kotlin.coroutines.SuspendFunction1)` will not resume execution when the sub coroutine finishes unless the `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle` is at least in `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.Lifecycle).whenStateAtLeast(androidx.lifecycle.Lifecycle.State,kotlin.coroutines.SuspendFunction1)`.

If the `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle` is destroyed while the `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.Lifecycle).whenStateAtLeast(androidx.lifecycle.Lifecycle.State,kotlin.coroutines.SuspendFunction1)` is suspended, the `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.Lifecycle).whenStateAtLeast(androidx.lifecycle.Lifecycle.State,kotlin.coroutines.SuspendFunction1)` will be cancelled which will also cancel any child coroutine launched inside the `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.Lifecycle).whenStateAtLeast(androidx.lifecycle.Lifecycle.State,kotlin.coroutines.SuspendFunction1)`.

If you have a `try finally` block in your code, the `finally` might run after the `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle` moves outside the desired state. It is recommended to check the `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle#currentState()` before accessing the UI. Similarly, if you have a `catch` statement that might catch `CancellationException`, you should check the `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle#currentState()` before accessing the UI. See the sample below for more details.

```kotlin
// running a block of code only if lifecycle is STARTED
viewLifecycle.whenStateAtLeast(Lifecycle.State.STARTED) {
    // here, we are on the main thread and view lifecycle is guaranteed to be STARTED or RESUMED.
    // We can safely access our views.
    loadingBar.visibility = View.VISIBLE
    try {
        // we can call any suspend function
        val data = withContext(Dispatchers.IO) {
            // this will run in IO thread pool. It will keep running as long as Lifecycle
            // is not DESTROYED. If it is destroyed, this coroutine will be cancelled as well.
            // However, we CANNOT access Views here.

            // We are using withContext(Dispatchers.IO) here just for demonstration purposes.
            // Such code should live in your business logic classes and your UI should use a
            // ViewModel (or similar) to access it.
            api.getUser()
        }
        // this line will execute on the main thread and only if the lifecycle is in at least
        // STARTED state (STARTED is the parameter we've passed to whenStateAtLeast)
        // Because of this guarantee, we can safely access the UI again.
        loadingBar.visibility = View.GONE
        nameTextView.text = user.name
        lastNameTextView.text = user.lastName
    } catch(ex : UserNotFoundException) {
        // same as above, this code can safely access UI elements because it only runs if
        // view lifecycle is at least STARTED
        loadingBar.visibility = View.GONE
        showErrorDialog(ex)
    } catch(th : Throwable) {
         // Unlike the catch statement above, this catch statements it too generic and might
         // also catch the CancellationException. Before accessing UI, you should check isActive
         // or lifecycle state
         if (viewLifecycle.currentState >= Lifecycle.State.STARTED) {
             // here you can access the view because you've checked the coroutine is active
         }
    } finally {
        // in case of cancellation, this line might run even if the Lifecycle is not DESTROYED.
        // You cannot access Views here unless you check `isActive` or lifecycle state
        if (viewLifecycle.currentState >= Lifecycle.State.STARTED) {
            // safe to access views
        } else {
            // not safe to access views
        }
    }
}
```

| Parameters |
|---|---|
| `minState: https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State` | The desired minimum state to run the `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.Lifecycle).whenStateAtLeast(androidx.lifecycle.Lifecycle.State,kotlin.coroutines.SuspendFunction1)`. |
| `block: suspend https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope/index.html.() -> T` | The block to run when the lifecycle is at least in `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.Lifecycle).whenStateAtLeast(androidx.lifecycle.Lifecycle.State,kotlin.coroutines.SuspendFunction1)`. |

| Returns |
|---|---|
| `T` | The return value of the \[block\] |

### Lifecycle.withCreated

Cmn Artifact: [androidx.lifecycle:lifecycle-runtime](https://developer.android.com/jetpack/androidx/releases/lifecycle) [View Source](https://cs.android.com/search?q=file:androidx/lifecycle/WithLifecycleState.kt+function:withCreated)

```
suspend inline fun <R : Any?> Lifecycle.withCreated(crossinline block: () -> R): R
```

Run `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.Lifecycle).withCreated(kotlin.Function0)` with this `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle` in a `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State` of at least `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State#CREATED` and resume with the result. Throws the `https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleDestroyedException` if the lifecycle has reached `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State#DESTROYED` by the time of the call or before `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.Lifecycle).withCreated(kotlin.Function0)` is able to run.

### LifecycleOwner.withCreated

Cmn Artifact: [androidx.lifecycle:lifecycle-runtime](https://developer.android.com/jetpack/androidx/releases/lifecycle) [View Source](https://cs.android.com/search?q=file:androidx/lifecycle/WithLifecycleState.kt+function:withCreated)

```
suspend inline fun <R : Any?> LifecycleOwner.withCreated(crossinline block: () -> R): R
```

Run `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.LifecycleOwner).withCreated(kotlin.Function0)` with this `https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleOwner`'s `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle` in a `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State` of at least `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State#CREATED` and resume with the result. Throws the `https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleDestroyedException` if the lifecycle has reached `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State#DESTROYED` by the time of the call or before `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.LifecycleOwner).withCreated(kotlin.Function0)` is able to run.

### Lifecycle.withResumed

Cmn Artifact: [androidx.lifecycle:lifecycle-runtime](https://developer.android.com/jetpack/androidx/releases/lifecycle) [View Source](https://cs.android.com/search?q=file:androidx/lifecycle/WithLifecycleState.kt+function:withResumed)

```
suspend inline fun <R : Any?> Lifecycle.withResumed(crossinline block: () -> R): R
```

Run `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.Lifecycle).withResumed(kotlin.Function0)` with this `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle` in a `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State` of at least `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State#RESUMED` and resume with the result. Throws the `https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleDestroyedException` if the lifecycle has reached `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State#DESTROYED` by the time of the call or before `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.Lifecycle).withResumed(kotlin.Function0)` is able to run.

### LifecycleOwner.withResumed

Cmn Artifact: [androidx.lifecycle:lifecycle-runtime](https://developer.android.com/jetpack/androidx/releases/lifecycle) [View Source](https://cs.android.com/search?q=file:androidx/lifecycle/WithLifecycleState.kt+function:withResumed)

```
suspend inline fun <R : Any?> LifecycleOwner.withResumed(crossinline block: () -> R): R
```

Run `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.LifecycleOwner).withResumed(kotlin.Function0)` with this `https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleOwner`'s `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle` in a `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State` of at least `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State#RESUMED` and resume with the result. Throws the `https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleDestroyedException` if the lifecycle has reached `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State#DESTROYED` by the time of the call or before `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.LifecycleOwner).withResumed(kotlin.Function0)` is able to run.

### Lifecycle.withStarted

Cmn Artifact: [androidx.lifecycle:lifecycle-runtime](https://developer.android.com/jetpack/androidx/releases/lifecycle) [View Source](https://cs.android.com/search?q=file:androidx/lifecycle/WithLifecycleState.kt+function:withStarted)

```
suspend inline fun <R : Any?> Lifecycle.withStarted(crossinline block: () -> R): R
```

Run `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.Lifecycle).withStarted(kotlin.Function0)` with this `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle` in a `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State` of at least `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State#STARTED` and resume with the result. Throws the `https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleDestroyedException` if the lifecycle has reached `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State#DESTROYED` by the time of the call or before `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.Lifecycle).withStarted(kotlin.Function0)` is able to run.

### LifecycleOwner.withStarted

Cmn Artifact: [androidx.lifecycle:lifecycle-runtime](https://developer.android.com/jetpack/androidx/releases/lifecycle) [View Source](https://cs.android.com/search?q=file:androidx/lifecycle/WithLifecycleState.kt+function:withStarted)

```
suspend inline fun <R : Any?> LifecycleOwner.withStarted(crossinline block: () -> R): R
```

Run `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.LifecycleOwner).withStarted(kotlin.Function0)` with this `https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleOwner`'s `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle` in a `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State` of at least `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State#STARTED` and resume with the result. Throws the `https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleDestroyedException` if the lifecycle has reached `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State#DESTROYED` by the time of the call or before `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.LifecycleOwner).withStarted(kotlin.Function0)` is able to run.

### Lifecycle.withStateAtLeast

Cmn Artifact: [androidx.lifecycle:lifecycle-runtime](https://developer.android.com/jetpack/androidx/releases/lifecycle) [View Source](https://cs.android.com/search?q=file:androidx/lifecycle/WithLifecycleState.kt+function:withStateAtLeast)

```
suspend inline fun <R : Any?> Lifecycle.withStateAtLeast(
    state: Lifecycle.State,
    crossinline block: () -> R
): R
```

Run `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.Lifecycle).withStateAtLeast(androidx.lifecycle.Lifecycle.State,kotlin.Function0)` with this `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle` in a `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State` of at least `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.Lifecycle).withStateAtLeast(androidx.lifecycle.Lifecycle.State,kotlin.Function0)` and resume with the result. Throws the `https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleDestroyedException` if the lifecycle has reached `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State#DESTROYED` by the time of the call or before `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.Lifecycle).withStateAtLeast(androidx.lifecycle.Lifecycle.State,kotlin.Function0)` is able to run.

### LifecycleOwner.withStateAtLeast

Cmn Artifact: [androidx.lifecycle:lifecycle-runtime](https://developer.android.com/jetpack/androidx/releases/lifecycle) [View Source](https://cs.android.com/search?q=file:androidx/lifecycle/WithLifecycleState.kt+function:withStateAtLeast)

```
suspend inline fun <R : Any?> LifecycleOwner.withStateAtLeast(
    state: Lifecycle.State,
    crossinline block: () -> R
): R
```

Run `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.LifecycleOwner).withStateAtLeast(androidx.lifecycle.Lifecycle.State,kotlin.Function0)` with this `https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleOwner`'s `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle` in a `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State` of at least `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.LifecycleOwner).withStateAtLeast(androidx.lifecycle.Lifecycle.State,kotlin.Function0)` and resume with the result. Throws the `https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleDestroyedException` if the lifecycle has reached `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State#DESTROYED` by the time of the call or before `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(androidx.lifecycle.LifecycleOwner).withStateAtLeast(androidx.lifecycle.Lifecycle.State,kotlin.Function0)` is able to run.

## Top-level properties

### DEFAULT_ARGS_KEY

Cmn Artifact: [androidx.lifecycle:lifecycle-viewmodel-savedstate](https://developer.android.com/jetpack/androidx/releases/lifecycle) [View Source](https://cs.android.com/search?q=file:androidx/lifecycle/SavedStateHandleSupport.kt+symbol:DEFAULT_ARGS_KEY) Added in [2.5.0](https://developer.android.com/jetpack/androidx/releases/lifecycle#2.5.0)

```
val DEFAULT_ARGS_KEY: CreationExtras.Key<SavedState>
```

A `https://developer.android.com/reference/kotlin/androidx/lifecycle/viewmodel/CreationExtras.Key` to retrieve the default `https://developer.android.com/reference/kotlin/androidx/savedstate/SavedState` arguments to be passed to the `https://developer.android.com/reference/kotlin/androidx/lifecycle/SavedStateHandle`.

### SAVED_STATE_REGISTRY_OWNER_KEY

Cmn Artifact: [androidx.lifecycle:lifecycle-viewmodel-savedstate](https://developer.android.com/jetpack/androidx/releases/lifecycle) [View Source](https://cs.android.com/search?q=file:androidx/lifecycle/SavedStateHandleSupport.kt+symbol:SAVED_STATE_REGISTRY_OWNER_KEY) Added in [2.5.0](https://developer.android.com/jetpack/androidx/releases/lifecycle#2.5.0)

```
val SAVED_STATE_REGISTRY_OWNER_KEY: CreationExtras.Key<SavedStateRegistryOwner>
```

A `https://developer.android.com/reference/kotlin/androidx/lifecycle/viewmodel/CreationExtras.Key` to retrieve the `https://developer.android.com/reference/kotlin/androidx/savedstate/SavedStateRegistryOwner` associated with the `https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModel` being created.

### VIEW_MODEL_STORE_OWNER_KEY

Cmn Artifact: [androidx.lifecycle:lifecycle-viewmodel-savedstate](https://developer.android.com/jetpack/androidx/releases/lifecycle) [View Source](https://cs.android.com/search?q=file:androidx/lifecycle/SavedStateHandleSupport.kt+symbol:VIEW_MODEL_STORE_OWNER_KEY) Added in [2.5.0](https://developer.android.com/jetpack/androidx/releases/lifecycle#2.5.0)

```
val VIEW_MODEL_STORE_OWNER_KEY: CreationExtras.Key<ViewModelStoreOwner>
```

A `https://developer.android.com/reference/kotlin/androidx/lifecycle/viewmodel/CreationExtras.Key` to retrieve the `https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModelStoreOwner` associated with the `https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModel` being created.

## Extension properties

### AndroidViewModel.application

android Artifact: [androidx.lifecycle:lifecycle-viewmodel](https://developer.android.com/jetpack/androidx/releases/lifecycle) [View Source](https://cs.android.com/search?q=file:androidx/lifecycle/AndroidViewModel.android.kt+symbol:application)

```
val AndroidViewModel.application: Application
```

Returns the underlying `https://developer.android.com/reference/android/app/Application.html` of the `https://developer.android.com/reference/kotlin/androidx/lifecycle/AndroidViewModel`.

Works around a Kotlin compilation issue where class hierarchies extending `https://developer.android.com/reference/kotlin/androidx/lifecycle/AndroidViewModel` (e.g., `KotlinViewModel` extending `JavaViewModel` extending `https://developer.android.com/reference/kotlin/androidx/lifecycle/AndroidViewModel`) incorrectly expose the private `application` property.

### Lifecycle.coroutineScope

Cmn 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.kt+symbol:coroutineScope) Added in [2.6.0](https://developer.android.com/jetpack/androidx/releases/lifecycle#2.6.0)

```
val Lifecycle.coroutineScope: LifecycleCoroutineScope
```

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

Canceled when the `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle` is destroyed. Bound to `Dispatchers.Main.immediate`.

### ViewModelStoreOwner.defaultViewModelCreationExtras

Cmn Artifact: [androidx.lifecycle:lifecycle-viewmodel](https://developer.android.com/jetpack/androidx/releases/lifecycle) [View Source](https://cs.android.com/search?q=file:androidx/lifecycle/ViewModelStoreOwnerDefaults.kt+symbol:defaultViewModelCreationExtras) Added in [2.11.0](https://developer.android.com/jetpack/androidx/releases/lifecycle#2.11.0)

```
val ViewModelStoreOwner?.defaultViewModelCreationExtras: CreationExtras
```

Returns the appropriate default `https://developer.android.com/reference/kotlin/androidx/lifecycle/viewmodel/CreationExtras` to use.

If the provided `https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModelStoreOwner` implements `https://developer.android.com/reference/kotlin/androidx/lifecycle/HasDefaultViewModelProviderFactory`, this will return its `https://developer.android.com/reference/kotlin/androidx/lifecycle/HasDefaultViewModelProviderFactory#defaultViewModelCreationExtras()`. Otherwise, or if `https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModelStoreOwner` is `null`, it falls back to `https://developer.android.com/reference/kotlin/androidx/lifecycle/viewmodel/CreationExtras.Empty`.

### ViewModelStoreOwner.defaultViewModelProviderFactory

Cmn Artifact: [androidx.lifecycle:lifecycle-viewmodel](https://developer.android.com/jetpack/androidx/releases/lifecycle) [View Source](https://cs.android.com/search?q=file:androidx/lifecycle/ViewModelStoreOwnerDefaults.kt+symbol:defaultViewModelProviderFactory) Added in [2.11.0](https://developer.android.com/jetpack/androidx/releases/lifecycle#2.11.0)

```
val ViewModelStoreOwner?.defaultViewModelProviderFactory: ViewModelProvider.Factory
```

Returns the appropriate default `https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModelProvider.Factory` to use.

If the provided `https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModelStoreOwner` implements `https://developer.android.com/reference/kotlin/androidx/lifecycle/HasDefaultViewModelProviderFactory`, this will return its `https://developer.android.com/reference/kotlin/androidx/lifecycle/HasDefaultViewModelProviderFactory#defaultViewModelProviderFactory()`. Otherwise, or if `https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModelStoreOwner` is `null`, it falls back to the standard .

### Lifecycle.eventFlow

Cmn 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.kt+symbol:eventFlow) Added in [2.7.0](https://developer.android.com/jetpack/androidx/releases/lifecycle#2.7.0)

```
val Lifecycle.eventFlow: Flow<Lifecycle.Event>
```

Creates a `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html` of `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.Event`s dispatched by this `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle`.

### LifecycleOwner.lifecycleScope

Cmn Artifact: [androidx.lifecycle:lifecycle-common](https://developer.android.com/jetpack/androidx/releases/lifecycle) [View Source](https://cs.android.com/search?q=file:androidx/lifecycle/LifecycleOwner.kt+symbol:lifecycleScope) Added in [2.6.0](https://developer.android.com/jetpack/androidx/releases/lifecycle#2.6.0)

```
val LifecycleOwner.lifecycleScope: LifecycleCoroutineScope
```

`https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope/index.html` tied to this `https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleOwner`'s `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle`.

Canceled when the `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle` is destroyed. Bound to `Dispatchers.Main.immediate`.

### ViewModel.viewModelScope

Cmn Artifact: [androidx.lifecycle:lifecycle-viewmodel](https://developer.android.com/jetpack/androidx/releases/lifecycle) [View Source](https://cs.android.com/search?q=file:androidx/lifecycle/ViewModel.kt+symbol:viewModelScope) Added in [2.8.0](https://developer.android.com/jetpack/androidx/releases/lifecycle#2.8.0)

```
val ViewModel.viewModelScope: CoroutineScope
```

The `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope/index.html` associated with this `https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModel`.

The `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope/coroutine-context.html` is configured with:

- `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/index.html`: ensures children jobs can fail independently of each other.

- `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-main-coroutine-dispatcher/immediate.html`: executes jobs immediately on the main (UI) thread. If the `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-dispatchers/-main.html` is not available on the current platform (e.g., Linux), we fall back to an `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-empty-coroutine-context/index.html`.

This scope is automatically canceled when the `https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModel` is cleared, and can be replaced by using the `https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModel` constructor overload that takes in a `viewModelScope: CoroutineScope`.

For background execution, use `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/index.html` to switch to appropriate dispatchers (e.g., `kotlinx.coroutines.IO`).

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModel#onCleared()` |   |