ViewModelProvider.Factory


public interface ViewModelProvider.Factory

Known direct subclasses
AbstractSavedStateViewModelFactory

Skeleton of androidx.lifecycle.ViewModelProvider.KeyedFactory that creates SavedStateHandle for every requested 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(
    @NonNull KClass<@NonNull T> modelClass,
    @NonNull CreationExtras extras
)

Creates a new instance of the given Class.

Public methods

create

Added in 2.8.0
default @NonNull T <T extends ViewModel> create(
    @NonNull KClass<@NonNull T> modelClass,
    @NonNull CreationExtras extras
)

Creates a new instance of the given Class.

Parameters
@NonNull KClass<@NonNull T> modelClass

a KClass whose instance is requested

@NonNull CreationExtras extras

an additional information for this creation request

Returns
@NonNull T

a newly created ViewModel