ViewModelProviders


public class ViewModelProviders


Utilities methods for ViewModelStore class.

Summary

Nested types

This class is deprecated.

Use ViewModelProvider.AndroidViewModelFactory

Public constructors

This method is deprecated.

This class should not be directly instantiated

Public methods

static @NonNull ViewModelProvider

This method is deprecated.

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

static @NonNull ViewModelProvider

This method is deprecated.

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

static @NonNull ViewModelProvider

This method is deprecated.

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

static @NonNull ViewModelProvider

This method is deprecated.

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

Public constructors

ViewModelProviders

Added in 2.0.0
Deprecated in 2.0.0
public ViewModelProviders()

Public methods

of

Added in 2.0.0
Deprecated in 2.2.0
@MainThread
public static @NonNull ViewModelProvider of(@NonNull FragmentActivity activity)

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
@NonNull FragmentActivity activity

an activity, in whose scope ViewModels should be retained

Returns
@NonNull ViewModelProvider

a ViewModelProvider instance

of

Added in 2.0.0
Deprecated in 2.2.0
@MainThread
public static @NonNull ViewModelProvider of(@NonNull Fragment fragment)

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
@NonNull Fragment fragment

a fragment, in whose scope ViewModels should be retained

Returns
@NonNull ViewModelProvider

a ViewModelProvider instance

of

Added in 2.0.0
Deprecated in 2.2.0
@MainThread
public static @NonNull ViewModelProvider of(
    @NonNull FragmentActivity activity,
    @Nullable 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 Factory to instantiate new ViewModels.

Parameters
@NonNull FragmentActivity activity

an activity, in whose scope ViewModels should be retained

@Nullable ViewModelProvider.Factory factory

a Factory to instantiate new ViewModels

Returns
@NonNull ViewModelProvider

a ViewModelProvider instance

of

Added in 2.0.0
Deprecated in 2.2.0
@MainThread
public static @NonNull ViewModelProvider of(@NonNull Fragment fragment, @Nullable 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 Factory to instantiate new ViewModels.

Parameters
@NonNull Fragment fragment

a fragment, in whose scope ViewModels should be retained

@Nullable ViewModelProvider.Factory factory

a Factory to instantiate new ViewModels

Returns
@NonNull ViewModelProvider

a ViewModelProvider instance