Register now for Android Dev Summit 2019!

AbstractSavedStateVMFactory

abstract class AbstractSavedStateVMFactory : KeyedFactory
androidx.lifecycle.AbstractSavedStateVMFactory

Skeleton of androidx.lifecycle.ViewModelProvider.KeyedFactory that creates SavedStateHandle for every requested ViewModel. The subclasses implement create(String, Class, SavedStateHandle) to actually instantiate ViewModels.

Summary

Public constructors

<init>(@NonNull owner: SavedStateRegistryOwner, @Nullable defaultArgs: Bundle?)

Constructs this factory.

Public methods

T
create(@NonNull modelClass: Class<T>)

Protected methods

abstract T
create(@NonNull key: String, @NonNull modelClass: Class<T>, @NonNull handle: SavedStateHandle)

Creates a new instance of the given Class.

Public constructors

<init>

AbstractSavedStateVMFactory(@NonNull owner: SavedStateRegistryOwner, @Nullable defaultArgs: Bundle?)

Constructs this factory.

Parameters
owner SavedStateRegistryOwner: SavedStateRegistryOwner that will provide restored state for created ViewModels
defaultArgs SavedStateRegistryOwner: values from this Bundle will be used as defaults by SavedStateHandle passed in ViewModels if there is no previously saved state or previously saved state misses a value by such key

Public methods

create

@NonNull fun <T : ViewModel!> create(@NonNull modelClass: Class<T>): T

Protected methods

create

@NonNull protected abstract fun <T : ViewModel!> create(@NonNull key: String, @NonNull modelClass: Class<T>, @NonNull handle: SavedStateHandle): T

Creates a new instance of the given Class.

Parameters
key String: a key associated with the requested ViewModel
modelClass String: a Class whose instance is requested
handle String: a handle to saved state associated with the requested ViewModel
<T> String: The type parameter for the ViewModel.
Return
T: a newly created ViewModels