SavedStateRegistry

public final class SavedStateRegistry
extends Object

java.lang.Object
   ↳ androidx.savedstate.SavedStateRegistry


An interface for plugging components that consumes and contributes to the saved state.

This objects lifetime is bound to the lifecycle of owning component: when activity or fragment is recreated, new instance of the object is created as well.

Summary

Nested classes

interface SavedStateRegistry.AutoRecreated

Subclasses of this interface will be automatically recreated if they were previously registered via SavedStateRegistry.runOnNextRecreation(Class)

interface SavedStateRegistry.SavedStateProvider

This interface marks a component that contributes to saved state. 

Public methods

Bundle consumeRestoredStateForKey(String key)

Consumes saved state previously supplied by SavedStateRegistry.SavedStateProvider registered via registerSavedStateProvider(String, SavedStateProvider) with the given key.

boolean isRestored()

Returns if state was restored after creation and can be safely consumed with consumeRestoredStateForKey(String)

void registerSavedStateProvider(String key, SavedStateRegistry.SavedStateProvider provider)

Registers a SavedStateRegistry.SavedStateProvider by the given key.

void runOnNextRecreation(Class<? extends SavedStateRegistry.AutoRecreated> clazz)

Executes the given class when the owning component restarted.

void unregisterSavedStateProvider(String key)

Unregisters a component previously registered by the given key

Inherited methods