ViewModelStore


public class ViewModelStore


Stores ViewModel instances by key.

A ViewModelStore instance must be retained across configuration changes. If an owner (typically a ViewModelStoreOwner) is destroyed and recreated due to a configuration change, the new owner must reuse the previous ViewModelStore instance.

When the owner is being destroyed permanently (i.e., it will not be recreated), it should call clear to notify all stored ViewModel instances that they are no longer needed (see ViewModel.onCleared).

Use ViewModelStoreOwner.viewModelStore to retrieve a ViewModelStore for activities and fragments.

Not stable for inheritance

This class is not intended for inheritance. It is technically open for binary compatibility with previous versions, but extending this class is unsupported.

Summary

Public constructors

Public methods

final void

Clears this store and notifies all stored ViewModel instances that they are no longer used.

@NonNull String

Public constructors

ViewModelStore

Added in 2.0.0
public ViewModelStore()

Public methods

clear

Added in 2.0.0
public final void clear()

Clears this store and notifies all stored ViewModel instances that they are no longer used.

After this call, the store is empty.

See also
onCleared

toString

public @NonNull String toString()