ViewModelLazy

public final class ViewModelLazy<VM extends ViewModel>


An implementation of Lazy used by androidx.fragment.app.Fragment.viewModels and androidx.activity.ComponentActivity.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

Summary

Public fields

@NonNull VM

Public constructors

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

Public methods

boolean

Public fields

value

@NonNull
public @NonNull VM value

Public constructors

ViewModelLazy

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

Public methods

isInitialized

@NonNull
public boolean isInitialized()