Android 12 Developer Preview is here! Try it out, and give us your feedback!

HiltViewModelFactory

public final class HiltViewModelFactory
extends AbstractSavedStateViewModelFactory

java.lang.Object
   ↳ androidx.lifecycle.AbstractSavedStateViewModelFactory
     ↳ androidx.hilt.lifecycle.HiltViewModelFactory


This class is deprecated.
References to this type and bindings to it should be removed. An equivalent factory to this is now provided out of the box by Hilt.

View Model Provider Factory for the Hilt Extension.

A provider for this factory will be installed in the ActivityComponent and FragmentComponent. An instance of this factory will also be the default factory by activities and fragments annotated with AndroidEntryPoint.

Summary

Protected methods

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

Creates a new instance of the given Class.

Inherited methods

Protected methods

create

protected T create (String key, 
                Class<T> modelClass, 
                SavedStateHandle handle)

Creates a new instance of the given Class.

Parameters
key String: a key associated with the requested ViewModel

modelClass Class: a Class whose instance is requested

handle SavedStateHandle: a handle to saved state associated with the requested ViewModel

Returns
T a newly created ViewModels