ViewModelProviders

open class ViewModelProviders
kotlin.Any
   ↳ androidx.lifecycle.ViewModelProviders

Utilities methods for ViewModelStore class.

Summary

Nested classes
open

Factory which may create AndroidViewModel and ViewModel, which have an empty constructor.

Public constructors

This class should not be directly instantiated

Public methods
open static ViewModelProvider
of(fragment: Fragment)

Creates a ViewModelProvider, which retains ViewModels while a scope of given fragment is alive.

open static ViewModelProvider
of(activity: FragmentActivity)

Creates a ViewModelProvider, which retains ViewModels while a scope of given Activity is alive.

open static ViewModelProvider
of(fragment: Fragment, factory: Factory?)

Creates a ViewModelProvider, which retains ViewModels while a scope of given fragment is alive.

open static ViewModelProvider
of(activity: FragmentActivity, factory: Factory?)

Creates a ViewModelProvider, which retains ViewModels while a scope of given Activity is alive.

Public constructors

<init>

ViewModelProviders()

Deprecated: This class should not be directly instantiated

Public methods

of

open static fun of(fragment: Fragment): ViewModelProvider

Creates a ViewModelProvider, which retains ViewModels while a scope of given fragment is alive. More detailed explanation is in ViewModel.

It uses ViewModelProvider.AndroidViewModelFactory to instantiate new ViewModels.

Parameters
fragment Fragment: a fragment, in whose scope ViewModels should be retained
Return
ViewModelProvider: a ViewModelProvider instance

of

open static fun of(activity: FragmentActivity): ViewModelProvider

Creates a ViewModelProvider, which retains ViewModels while a scope of given Activity is alive. More detailed explanation is in ViewModel.

It uses ViewModelProvider.AndroidViewModelFactory to instantiate new ViewModels.

Parameters
activity Fragment: an activity, in whose scope ViewModels should be retained
Return
ViewModelProvider: a ViewModelProvider instance

of

open static fun of(fragment: Fragment, factory: Factory?): ViewModelProvider

Creates a ViewModelProvider, which retains ViewModels while a scope of given fragment is alive. More detailed explanation is in ViewModel.

It uses the given Factory to instantiate new ViewModels.

Parameters
fragment Fragment: a fragment, in whose scope ViewModels should be retained
factory Fragment: a Factory to instantiate new ViewModels
Return
ViewModelProvider: a ViewModelProvider instance

of

open static fun of(activity: FragmentActivity, factory: Factory?): ViewModelProvider

Creates a ViewModelProvider, which retains ViewModels while a scope of given Activity is alive. More detailed explanation is in ViewModel.

It uses the given Factory to instantiate new ViewModels.

Parameters
activity Fragment: an activity, in whose scope ViewModels should be retained
factory Fragment: a Factory to instantiate new ViewModels
Return
ViewModelProvider: a ViewModelProvider instance