ViewModelKt

Added in 2.8.0-beta01

public final class ViewModelKt


Summary

Public methods

static final @NonNull CoroutineScope

The CoroutineScope associated with this ViewModel.

Public methods

getViewModelScope

public static final @NonNull CoroutineScope getViewModelScope(@NonNull ViewModel receiver)

The CoroutineScope associated with this ViewModel.

The CoroutineScope.coroutineContext is configured with:

This scope is automatically cancelled when the ViewModel is cleared, and can be replaced by using the ViewModel constructor overload that takes in a viewModelScope: CoroutineScope.

For background execution, use kotlinx.coroutines.withContext to switch to appropriate dispatchers (e.g., kotlinx.coroutines.IO).

See also
onCleared