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

clear

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.

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 2026-02-25 UTC.