Stay organized with collections
Save and categorize content based on your preferences.
added in
version 1.0.0
belongs to Maven artifact android.arch.lifecycle:viewmodel:1.1.1
ViewModelStore
public
class
ViewModelStore
extends Object
java.lang.Object
|
↳ |
android.arch.lifecycle.ViewModelStore
|
Class to store ViewModels
.
An instance of ViewModelStore
must be retained through configuration changes:
if an owner of this ViewModelStore
is destroyed and recreated due to configuration
changes, new instance of an owner should still have the same old instance of
ViewModelStore
.
If an owner of this ViewModelStore
is destroyed and is not going to be recreated,
then it should call clear()
on this ViewModelStore
, so ViewModels
would
be notified that they are no longer used.
ViewModelStores
provides a ViewModelStore
for
activities and fragments.
Summary
Public methods |
final
void
|
clear()
Clears internal storage and notifies ViewModels that they are no longer used.
|
Inherited methods |
From class
java.lang.Object
Object
|
clone()
|
boolean
|
equals(Object arg0)
|
void
|
finalize()
|
final
Class<?>
|
getClass()
|
int
|
hashCode()
|
final
void
|
notify()
|
final
void
|
notifyAll()
|
String
|
toString()
|
final
void
|
wait(long arg0, int arg1)
|
final
void
|
wait(long arg0)
|
final
void
|
wait()
|
|
Public constructors
ViewModelStore
ViewModelStore ()
Public methods
clear
void clear ()
Clears internal storage and notifies ViewModels that they are no longer used.
Annotations
Interfaces
Classes
Enums
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-02-10 UTC."],[],[],null,["# ViewModelStore\n\nadded in [version 1.0.0](/topic/libraries/support-library/revisions) \nbelongs to Maven artifact android.arch.lifecycle:viewmodel:1.1.1 \nSummary: [Ctors](#pubctors) \\| [Methods](#pubmethods) \\| [Inherited Methods](#inhmethods) \n\nViewModelStore\n==============\n\n| The `android.arch` Architecture Components packages are no longer maintained. They have been superseded by the corresponding [androidx.\\*](/jetpack/androidx/migrate) packages. See [androidx.lifecycle.ViewModelStore](/reference/androidx/lifecycle/ViewModelStore) instead.\n\n\n`\npublic\n\n\nclass\nViewModelStore\n`\n\n\n`\n\nextends Object\n\n\n`\n\n`\n\n\n`\n\n|---|---------------------------------------|\n| java.lang.Object ||\n| ↳ | android.arch.lifecycle.ViewModelStore |\n\n\u003cbr /\u003e\n\n*** ** * ** ***\n\nClass to store `ViewModels`.\n\n\nAn instance of `ViewModelStore` must be retained through configuration changes:\nif an owner of this `ViewModelStore` is destroyed and recreated due to configuration\nchanges, new instance of an owner should still have the same old instance of\n`ViewModelStore`.\n\n\nIf an owner of this `ViewModelStore` is destroyed and is not going to be recreated,\nthen it should call [clear()](/reference/android/arch/lifecycle/ViewModelStore#clear()) on this `ViewModelStore`, so `ViewModels` would\nbe notified that they are no longer used.\n\n\n[ViewModelStores](/reference/android/arch/lifecycle/ViewModelStores) provides a `ViewModelStore` for\nactivities and fragments.\n\nSummary\n-------\n\n| ### Public constructors ||\n|---------------------------------------------------------------------------------------------|---|\n| ` `[ViewModelStore](/reference/android/arch/lifecycle/ViewModelStore#ViewModelStore())`() ` |\n\n| ### Public methods ||\n|---------------|---------------------------------------------------------------------------------------------------------------------------------------------------------|\n| ` final void` | ` `[clear](/reference/android/arch/lifecycle/ViewModelStore#clear())`() ` Clears internal storage and notifies ViewModels that they are no longer used. |\n\n| ### Inherited methods |\n|-----------------------|---|\n| From class ` java.lang.Object ` |-------------------|-------------------------------| | ` Object` | ` clone() ` | | ` boolean` | ` equals(Object arg0) ` | | ` void` | ` finalize() ` | | ` final Class\u003c?\u003e` | ` getClass() ` | | ` int` | ` hashCode() ` | | ` final void` | ` notify() ` | | ` final void` | ` notifyAll() ` | | ` String` | ` toString() ` | | ` final void` | ` wait(long arg0, int arg1) ` | | ` final void` | ` wait(long arg0) ` | | ` final void` | ` wait() ` | ||\n\nPublic constructors\n-------------------\n\n### ViewModelStore\n\nadded in [version 1.0.0](/topic/libraries/support-library/revisions) \n\n```\nViewModelStore ()\n```\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nPublic methods\n--------------\n\n### clear\n\nadded in [version 1.0.0](/topic/libraries/support-library/revisions) \n\n```\nvoid clear ()\n```\n\nClears internal storage and notifies ViewModels that they are no longer used.\n\n\u003cbr /\u003e\n\n-\n\n Annotations\n -----------\n\n - [OnLifecycleEvent](/reference/android/arch/lifecycle/OnLifecycleEvent)\n-\n\n Interfaces\n ----------\n\n - [DefaultLifecycleObserver](/reference/android/arch/lifecycle/DefaultLifecycleObserver)\n - [LifecycleObserver](/reference/android/arch/lifecycle/LifecycleObserver)\n - [LifecycleOwner](/reference/android/arch/lifecycle/LifecycleOwner)\n - [LifecycleRegistryOwner](/reference/android/arch/lifecycle/LifecycleRegistryOwner)\n - [Observer](/reference/android/arch/lifecycle/Observer)\n - [ViewModelProvider.Factory](/reference/android/arch/lifecycle/ViewModelProvider.Factory)\n - [ViewModelStoreOwner](/reference/android/arch/lifecycle/ViewModelStoreOwner)\n-\n\n Classes\n -------\n\n - [AndroidViewModel](/reference/android/arch/lifecycle/AndroidViewModel)\n - [Lifecycle](/reference/android/arch/lifecycle/Lifecycle)\n - [LifecycleRegistry](/reference/android/arch/lifecycle/LifecycleRegistry)\n - [LifecycleService](/reference/android/arch/lifecycle/LifecycleService)\n - [LiveData](/reference/android/arch/lifecycle/LiveData)\n - [LiveDataReactiveStreams](/reference/android/arch/lifecycle/LiveDataReactiveStreams)\n - [MediatorLiveData](/reference/android/arch/lifecycle/MediatorLiveData)\n - [MutableLiveData](/reference/android/arch/lifecycle/MutableLiveData)\n - [ProcessLifecycleOwner](/reference/android/arch/lifecycle/ProcessLifecycleOwner)\n - [ServiceLifecycleDispatcher](/reference/android/arch/lifecycle/ServiceLifecycleDispatcher)\n - [Transformations](/reference/android/arch/lifecycle/Transformations)\n - [ViewModel](/reference/android/arch/lifecycle/ViewModel)\n - [ViewModelProvider](/reference/android/arch/lifecycle/ViewModelProvider)\n - [ViewModelProvider.AndroidViewModelFactory](/reference/android/arch/lifecycle/ViewModelProvider.AndroidViewModelFactory)\n - [ViewModelProvider.NewInstanceFactory](/reference/android/arch/lifecycle/ViewModelProvider.NewInstanceFactory)\n - [ViewModelProviders](/reference/android/arch/lifecycle/ViewModelProviders)\n - [ViewModelProviders.DefaultFactory](/reference/android/arch/lifecycle/ViewModelProviders.DefaultFactory)\n - [ViewModelStore](/reference/android/arch/lifecycle/ViewModelStore)\n - [ViewModelStores](/reference/android/arch/lifecycle/ViewModelStores)\n-\n\n Enums\n -----\n\n - [Lifecycle.Event](/reference/android/arch/lifecycle/Lifecycle.Event)\n - [Lifecycle.State](/reference/android/arch/lifecycle/Lifecycle.State)"]]