androidx.savedstate

Interfaces

SavedStateRegistry.AutoRecreated

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

SavedStateRegistry.SavedStateProvider

This interface marks a component that contributes to saved state.

SavedStateRegistryOwner

A scope that owns SavedStateRegistry

Classes

SavedStateRegistry

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

SavedStateRegistryController

An API for SavedStateRegistryOwner implementations to control SavedStateRegistry.

Extension functions summary

SavedStateRegistryOwner?

Retrieve the SavedStateRegistryOwner responsible for managing the saved state for this View.

Unit

Set the SavedStateRegistryOwner responsible for managing the saved state for this View Calls to get from this view or descendants will return owner.

Extension functions

findViewTreeSavedStateRegistryOwner

fun View.findViewTreeSavedStateRegistryOwner(): SavedStateRegistryOwner?

Retrieve the SavedStateRegistryOwner responsible for managing the saved state for this View. This may be used to save or restore the state associated with the view.

The returned SavedStateRegistryOwner is managing all the Views within the Fragment or Activity this View is added to.

Returns
SavedStateRegistryOwner?

The SavedStateRegistryOwner responsible for managing the saved state for this view and/or some subset of its ancestors

setViewTreeSavedStateRegistryOwner

fun View.setViewTreeSavedStateRegistryOwner(
    owner: SavedStateRegistryOwner?
): Unit

Set the SavedStateRegistryOwner responsible for managing the saved state for this View Calls to get from this view or descendants will return owner.

This is is automatically set for you in the common cases of using fragments or ComponentActivity.

This should only be called by constructs such as activities or fragments that manage a view tree and their saved state through a SavedStateRegistryOwner. Callers should only set a SavedStateRegistryOwner that will be stable. The associated SavedStateRegistry should be cleared if the view tree is removed and is not guaranteed to later become reattached to a window.

Parameters
owner: SavedStateRegistryOwner?

The SavedStateRegistryOwner responsible for managing the saved state for the given view