public final class 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

Public methods

consumeRestoredStateForKey

@MainThread
public final SavedState consumeRestoredStateForKey(@NonNull String key)

Consumes saved state previously supplied by SavedStateProvider registered via registerSavedStateProvider with the given key.

This call clears an internal reference to returned saved state, so if you call it second time in the row it will return null.

All unconsumed values will be saved during onSaveInstanceState(SavedState savedState)

This method can be called after super.onCreate(savedStateBundle) of the corresponding component. Calling it before that will result in IllegalArgumentException. Lifecycle.Event.ON_CREATE can be used as a signal that a saved state can be safely consumed.

Returns
SavedState

S with the previously saved state or {@code null}

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-19 UTC.