SavedStateViewModelFactory
class SavedStateViewModelFactory : KeyedFactory
androidx.lifecycle.SavedStateViewModelFactory |
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
.
If ViewModel is instance of androidx.lifecycle.AndroidViewModel
, it looks for a constructor that receives an Application
and SavedStateHandle
(in this order), otherwise it looks for a constructor that receives SavedStateHandle
only.
Summary
Public constructors |
|
---|---|
<init>(@NonNull application: Application, @NonNull owner: SavedStateRegistryOwner) Creates |
|
<init>(@NonNull application: Application, @NonNull owner: SavedStateRegistryOwner, @Nullable defaultArgs: Bundle?) Creates |
Public methods |
|
---|---|
T | |
T |
Public constructors
<init>
SavedStateViewModelFactory(@NonNull application: Application, @NonNull owner: SavedStateRegistryOwner)
Creates SavedStateViewModelFactory
.
androidx.lifecycle.ViewModel
created with this factory can access to saved state scoped to the given activity
.
Parameters | |
---|---|
application |
Application: an application |
owner |
Application: SavedStateRegistryOwner that will provide restored state for created ViewModels |
<init>
SavedStateViewModelFactory(@NonNull application: Application, @NonNull owner: SavedStateRegistryOwner, @Nullable defaultArgs: Bundle?)
Creates SavedStateViewModelFactory
.
androidx.lifecycle.ViewModel
created with this factory can access to saved state scoped to the given activity
.
Parameters | |
---|---|
application |
Application: an application |
owner |
Application: SavedStateRegistryOwner that will provide restored state for created ViewModels |
defaultArgs |
Application: values from this Bundle will be used as defaults by SavedStateHandle if there is no previously saved state or previously saved state misses a value by such key. |