androidx.savedstate


Interfaces

SavedStateRegistry.AutoRecreated

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

android
SavedStateRegistry.SavedStateProvider

This interface marks a component that contributes to saved state.

Cmn
android
SavedStateRegistryOwner

A scope that owns SavedStateRegistry

Cmn

Classes

SavedState

An opaque (empty) common type that holds saveable values to be saved and restored by native platforms that have a concept of System-initiated Process Death.

Cmn
android
SavedStateReader

An inline class that encapsulates an opaque SavedState, and provides an API for reading the platform specific state.

Cmn
android
SavedStateRegistry

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

Cmn
android
SavedStateRegistryController

An API for SavedStateRegistryOwner implementations to control SavedStateRegistry.

Cmn
android
SavedStateWriter

An inline class that encapsulates an opaque SavedState, and provides an API for writing the platform specific state.

Cmn
android

Type aliases

SavedState
android

Top-level functions summary

inline SavedState

Constructs an empty SavedState instance.

Cmn
android

Extension functions summary

SavedStateRegistryOwner?

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

android
inline T
<T : Any?> SavedState.read(block: SavedStateReader.() -> T)

Calls the specified function block with a SavedStateReader value as its receiver and returns the block value.

Cmn
inline T
<T : Any?> SavedStateWriter.read(block: SavedStateReader.() -> T)

Calls the specified function block with a SavedStateReader value as its receiver and returns the block value.

Cmn
SavedStateReader

Creates a new SavedStateReader for the SavedState.

Cmn
Unit

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

android
inline T
<T : Any?> SavedState.write(block: SavedStateWriter.() -> T)

Calls the specified function block with a SavedStateWriter value as its receiver and returns the block value.

Cmn
inline T
<T : Any?> SavedStateReader.write(block: SavedStateWriter.() -> T)

Calls the specified function block with a SavedStateWriter value as its receiver and returns the block value.

Cmn
SavedStateWriter

Creates a new SavedStateWriter for the SavedState.

Cmn

Top-level functions

savedState

inline fun savedState(block: SavedStateWriter.() -> Unit = {}): SavedState

Constructs an empty SavedState instance.

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

inline fun <T : Any?> SavedState.read(block: SavedStateReader.() -> T): T

Calls the specified function block with a SavedStateReader value as its receiver and returns the block value.

Parameters
block: SavedStateReader.() -> T

A lambda function that performs read operations using the SavedStateReader.

Returns
T

The result of the lambda function's execution.

inline fun <T : Any?> SavedStateWriter.read(block: SavedStateReader.() -> T): T

Calls the specified function block with a SavedStateReader value as its receiver and returns the block value.

Parameters
block: SavedStateReader.() -> T

A lambda function that performs read operations using the SavedStateReader.

Returns
T

The result of the lambda function's execution.

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

inline fun <T : Any?> SavedState.write(block: SavedStateWriter.() -> T): T

Calls the specified function block with a SavedStateWriter value as its receiver and returns the block value.

Parameters
block: SavedStateWriter.() -> T

A lambda function that performs write operations using the SavedStateWriter.

Returns
T

The result of the lambda function's execution.

inline fun <T : Any?> SavedStateReader.write(block: SavedStateWriter.() -> T): T

Calls the specified function block with a SavedStateWriter value as its receiver and returns the block value.

Parameters
block: SavedStateWriter.() -> T

A lambda function that performs write operations using the SavedStateWriter.

Returns
T

The result of the lambda function's execution.