initialize

fun <O : ViewModelStoreOwner, HasDefaultViewModelProviderFactory> initialize(viewModelStoreOwner: O, viewModelClass: KClass<VM>, factoryAvailable: Boolean)

Initialize the delegated view model by either restoring or storing it in the ViewModelStore of the ViewModelStoreOwner.

The view model will be retrieved from the store or, when not found, a new instance of VM will be constructed by calling the factory and then stored.

Parameters

viewModelStoreOwner

The owner of the store.

viewModelClass

The KClass information of the VM.

factoryAvailable

If true it indicates the factory will be able to construct a new view model. If false, HasDefaultViewModelProviderFactory.getDefaultViewModelProviderFactory will not be called upon and instead requires the view model to already be stored. This is useful in situations such as those where a fragment has a lateinit var that is populated with information from the view model during recreation.