ViewModelProvider.Factory

interface ViewModelProvider.Factory

Known direct subclasses
AbstractSavedStateViewModelFactory

Skeleton of androidx.lifecycle.ViewModelProvider.KeyedFactory that creates SavedStateHandle for every requested androidx.lifecycle.ViewModel.

SavedStateViewModelFactory

androidx.lifecycle.ViewModelProvider.Factory that can create ViewModels accessing and contributing to a saved state via SavedStateHandle received in a constructor.

ViewModelProvider.NewInstanceFactory

Simple factory, which calls empty constructor on the give class.


Implementations of Factory interface are responsible to instantiate ViewModels.

Summary

Public methods

default @NonNull T
<T extends ViewModel> create(Class<T> modelClass)

Creates a new instance of the given Class.

default @NonNull T
<T extends ViewModel> create(Class<T> modelClass, CreationExtras extras)

Creates a new instance of the given Class.

Public methods

create

default @NonNull T <T extends ViewModel> create(Class<T> modelClass)

Creates a new instance of the given Class.

Default implementation throws UnsupportedOperationException.

Parameters
Class<T> modelClass

a Class whose instance is requested

Returns
@NonNull T

a newly created ViewModel

create

default @