ViewModelProviders



Utilities methods for ViewModelStore class.

Summary

Nested types

This class is deprecated.

Use ViewModelProvider.AndroidViewModelFactory

Public constructors

This function is deprecated.

This class should not be directly instantiated

android

Public functions

java-static ViewModelProvider

This function is deprecated.

Use the 'by viewModels()' Kotlin property delegate or ViewModelProvider, passing in the activity.

android
java-static ViewModelProvider
@MainThread
of(fragment: Fragment)

This function is deprecated.

Use the 'by viewModels()' Kotlin property delegate or ViewModelProvider, passing in the fragment.

android
java-static ViewModelProvider

This function is deprecated.

Use the 'by viewModels()' Kotlin property delegate or ViewModelProvider, passing in the activity and factory.

android
java-static ViewModelProvider

This function is deprecated.

Use the 'by viewModels()' Kotlin property delegate or ViewModelProvider, passing in the fragment and factory.

android

Public constructors

ViewModelProviders

ViewModelProviders()

Public functions

of

@MainThread
java-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 the default factory to instantiate new ViewModels.

Parameters
activity: FragmentActivity

an activity, in whose scope ViewModels should be retained

Returns
ViewModelProvider

a ViewModelProvider instance

of

@MainThread
java-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 the default factory to instantiate new ViewModels.

Parameters
fragment: Fragment

a fragment, in whose scope ViewModels should be retained

Returns
ViewModelProvider

a ViewModelProvider instance

of

@MainThread
java-static fun of(activity: FragmentActivity, factory: ViewModelProvider.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: FragmentActivity

an activity, in whose scope ViewModels should be retained

factory: ViewModelProvider.Factory?

a Factory to instantiate new ViewModels

Returns
ViewModelProvider

a ViewModelProvider instance

of

@MainThread
java-static fun of(fragment: Fragment, factory: ViewModelProvider.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: ViewModelProvider.Factory?

a Factory to instantiate new ViewModels

Returns
ViewModelProvider

a ViewModelProvider instance