Skip to content

Most visited

Recently visited

navigation
added in version 1.0.0
belongs to Maven artifact android.arch.lifecycle:extensions:1.0.0

ViewModelProviders

public class ViewModelProviders
extends Object

java.lang.Object
   ↳ android.arch.lifecycle.ViewModelProviders


Utilities methods for ViewModelStore class.

Summary

Nested classes

class ViewModelProviders.DefaultFactory

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

Public constructors

ViewModelProviders()

Public methods

static ViewModelProvider of(Fragment fragment)

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

static ViewModelProvider of(FragmentActivity activity)

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

static ViewModelProvider of(Fragment fragment, ViewModelProvider.Factory factory)

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

static ViewModelProvider of(FragmentActivity activity, ViewModelProvider.Factory factory)

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

Inherited methods

From class java.lang.Object

Public constructors

ViewModelProviders

added in version 1.0.0
ViewModelProviders ()

Public methods

of

added in version 1.0.0
ViewModelProvider of (Fragment fragment)

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

It uses ViewModelProviders.DefaultFactory to instantiate new ViewModels.

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

Returns
ViewModelProvider a ViewModelProvider instance

of

added in version 1.0.0
ViewModelProvider of (FragmentActivity activity)

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

It uses ViewModelProviders.DefaultFactory to instantiate new ViewModels.

Parameters
activity FragmentActivity: an activity, in whose scope ViewModels should be retained

Returns
ViewModelProvider a ViewModelProvider instance

of

added in version 1.0.0
ViewModelProvider of (Fragment fragment, 
                ViewModelProvider.Factory factory)

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

It uses the given ViewModelProvider.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

of

added in version 1.0.0
ViewModelProvider of (FragmentActivity activity, 
                ViewModelProvider.Factory factory)

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

It uses the given ViewModelProvider.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

This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields

Hooray!

Follow Google Developers on WeChat

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a short survey?
Help us improve the Android developer experience. (Dec 2017 Android Platform & Tools Survey)