ViewModelProviderUtil

object ViewModelProviderUtil

Object containing methods to simplify the interaction with the ViewModelProvider.

Functions

Link copied to clipboard
fun <T : ViewModel> getOrCreate(    owner: ViewModelStoreOwner,     kotlinClass: KClass<*>,     key: String,     factory: ViewModelProvider.Factory? = null): T

Returns an existing ViewModel from the ViewModelStore owned by the ViewModelStoreOwner. If no existing ViewModel is in the store it creates a new one using a factory provided in factory. If factory is null a factory will be retrieved by calling HasDefaultViewModelProviderFactory.getDefaultViewModelProviderFactory on the ViewModelStoreOwner or a default factory will be used expecting a parameter-less constructor for kotlinClass.

Link copied to clipboard
fun <T : ViewModel> getOrThrow(    owner: ViewModelStoreOwner,     kotlinClass: KClass<*>,     key: String): T

Returns an existing ViewModel or throws an exception when no matching view model can be restored.