SavedStateViewModelFactory
public final class SavedStateViewModelFactory implements ViewModelProvider.Factory
androidx.lifecycle.ViewModelProvider.Factory that can create ViewModels accessing and contributing to a saved state via SavedStateHandle received in a constructor. If defaultArgs bundle was passed into the constructor, it will provide default values in SavedStateHandle.
Summary
Public constructors |
|---|
|
Constructs this factory. |
SavedStateViewModelFactory(Creates |
SavedStateViewModelFactory(Creates |
Public methods |
|
|---|---|
@NonNull T |
Public constructors
SavedStateViewModelFactory
public SavedStateViewModelFactory()
Constructs this factory.
When a factory is constructed this way, a component for which SavedStateHandle is scoped must have called enableSavedStateHandles.
| See also | |
|---|---|
createSavedStateHandle |
docs for more details. |
SavedStateViewModelFactory
public SavedStateViewModelFactory(
Application application,
@NonNull SavedStateRegistryOwner owner
)
Creates SavedStateViewModelFactory.
androidx.lifecycle.ViewModel created with this factory can access to saved state scoped to the given activity.
| Parameters | |
|---|---|
Application application |
an application. If null, |
@NonNull SavedStateRegistryOwner owner |
|
SavedStateViewModelFactory
public SavedStateViewModelFactory(
Application application,
@NonNull SavedStateRegistryOwner owner,
Bundle defaultArgs
)
Creates SavedStateViewModelFactory.
androidx.lifecycle.ViewModel created with this factory can access to saved state scoped to the given activity.
When a factory is constructed this way, if you add any CreationExtras those arguments will be used instead of the state passed in here. It is not possible to mix the arguments received here with the CreationExtras.
| Parameters | |
|---|---|
Application application |
an application. If null, |
@NonNull SavedStateRegistryOwner owner |
|
Bundle defaultArgs |
values from this |