injectedViewModel

inline fun <VM : ViewModel> ComponentActivity.injectedViewModel(    noinline extrasProducer: () -> CreationExtras = { defaultViewModelCreationExtras }): Lazy<VM>

ComponentActivity.viewModels that uses application's ViewModelProvider.Factory


inline fun <VM : ViewModel> injectedViewModel(    viewModelStoreOwner: ViewModelStoreOwner = checkNotNull(LocalViewModelStoreOwner.current) { "No ViewModelStoreOwner was provided via LocalViewModelStoreOwner" },     key: String? = null,     extras: CreationExtras = if (viewModelStoreOwner is HasDefaultViewModelProviderFactory) { viewModelStoreOwner.defaultViewModelCreationExtras } else { CreationExtras.Empty }): VM

Returns an existing ViewModel or creates a new one in the given owner (usually, a fragment or an activity), defaulting to the owner provided by LocalViewModelStoreOwner.

The created ViewModel is associated with the given viewModelStoreOwner and will be retained as long as the owner is alive (e.g. if it is an activity, until it is finished or process is killed).

If default arguments are provided via the CreationExtras, they will be available to the appropriate factory when the ViewModel is created.

Application's ViewModelProvider.Factory will be used to create the ViewModel.

Return

A ViewModel that is an instance of the given VM type.

Parameters

viewModelStoreOwner

The owner of the ViewModel that controls the scope and lifetime of the returned ViewModel. Defaults to using LocalViewModelStoreOwner.

key

The key to use to identify the ViewModel.

extras

The default extras used to create the ViewModel.


fun <VM : ViewModel> injectedViewModel(    modelClass: Class<VM>,     viewModelStoreOwner: ViewModelStoreOwner = checkNotNull(LocalViewModelStoreOwner.current) { "No ViewModelStoreOwner was provided via LocalViewModelStoreOwner" },     key: String? = null,     extras: CreationExtras = if (viewModelStoreOwner is HasDefaultViewModelProviderFactory) { viewModelStoreOwner.defaultViewModelCreationExtras } else { CreationExtras.Empty }): VM

Returns an existing ViewModel or creates a new one in the scope (usually, a fragment or an activity)

The created ViewModel is associated with the given viewModelStoreOwner and will be retained as long as the scope is alive (e.g. if it is an activity, until it is finished or process is killed).

If default arguments are provided via the CreationExtras, they will be available to the appropriate factory when the ViewModel is created.

Application's ViewModelProvider.Factory will be used to create the ViewModel.

Return

A ViewModel that is an instance of the given VM type.

Parameters

modelClass

The class of the ViewModel to create an instance of it if it is not present.

viewModelStoreOwner

The scope that the created ViewModel should be associated with.

key

The key to use to identify the ViewModel.

extras

The default extras used to create the ViewModel.


inline fun <VM : ViewModel> Fragment.injectedViewModel(    noinline ownerProducer: () -> ViewModelStoreOwner = { this },     noinline extrasProducer: () -> CreationExtras? = null): Lazy<VM>

Fragment.viewModels that uses application's ViewModelProvider.Factory