SavedStateViewModelFactory

public final class SavedStateViewModelFactory
extends ViewModelProvider.KeyedFactory

java.lang.Object
   ↳ androidx.lifecycle.ViewModelProvider.OnRequeryFactory
     ↳ androidx.lifecycle.ViewModelProvider.KeyedFactory
       ↳ androidx.lifecycle.SavedStateViewModelFactory


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 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. AndroidViewModel is only supported if you pass a non-null Application instance.

Summary

Public constructors

SavedStateViewModelFactory(Application application, SavedStateRegistryOwner owner)

Creates SavedStateViewModelFactory.

SavedStateViewModelFactory(Application application, SavedStateRegistryOwner owner, Bundle defaultArgs)

Creates SavedStateViewModelFactory.

Public methods

<T extends ViewModel> T create(String key, Class<T> modelClass)
<T extends ViewModel> T create(Class<T> modelClass)

Inherited methods