ViewModelLazy


public final class ViewModelLazy<VM extends ViewModel> implements Lazy


An implementation of Lazy used by androidx.fragment.app.viewModels and androidx.activity.viewModels.

storeProducer is a lambda that will be called during initialization, VM will be created in the scope of returned ViewModelStore.

factoryProducer is a lambda that will be called during initialization, returned ViewModelProvider.Factory will be used for creation of VM

extrasProducer is a lambda that will be called during initialization, returned HasDefaultViewModelProviderFactory will get CreationExtras used for creation of VM

Summary

Public constructors

<VM extends ViewModel> ViewModelLazy(
    @NonNull KClass<@NonNull VM> viewModelClass,
    @NonNull Function0<@NonNull ViewModelStore> storeProducer,
    @NonNull Function0<@NonNull ViewModelProvider.Factory> factoryProducer,
    @NonNull Function0<@NonNull CreationExtras> extrasProducer
)

Public methods

@NonNull VM
boolean

Public constructors

ViewModelLazy

public <VM extends ViewModel> ViewModelLazy(
    @NonNull KClass<@NonNull VM> viewModelClass,
    @NonNull Function0<@NonNull ViewModelStore> storeProducer,
    @NonNull Function0<@NonNull ViewModelProvider.Factory> factoryProducer,
    @NonNull Function0<@NonNull CreationExtras> extrasProducer
)

Public methods

getValue

Added in 2.4.0
public @NonNull VM getValue()

isInitialized

Added in 2.4.0
public boolean isInitialized()