androidx.savedstate
Interfaces
SavedStateRegistry.AutoRecreated |
Subclasses of this interface will be automatically recreated if they were previously registered via |
android
|
SavedStateRegistry.SavedStateProvider |
This interface marks a component that contributes to saved state. |
Cmn
android
|
SavedStateRegistryOwner |
A scope that owns |
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 |
Cmn
android
|
SavedStateRegistry |
An interface for plugging components that consumes and contributes to the saved state. |
Cmn
android
|
SavedStateRegistryController |
An API for |
Cmn
android
|
SavedStateWriter |
An inline class that encapsulates an opaque |
Cmn
android
|
Type aliases
SavedState |
android
|
Top-level functions summary
inline SavedState |
savedState(initialState: Map<String, Any?>, builderAction: SavedStateWriter.() -> Unit)Builds a new |
Cmn
android
|
inline Bundle |
savedState(initialState: Bundle, builderAction: SavedStateWriter.() -> Unit) |
android
|
inline SavedState |
savedState(initialState: SavedState, builderAction: SavedStateWriter.() -> Unit)Builds a new |
Cmn
android
|
Extension functions summary
SavedStateRegistryOwner? |
Retrieve the |
android
|
inline T |
<T : Any?> SavedState.read(block: SavedStateReader.() -> T)Calls the specified function |
Cmn
|
Unit |
Set the |
android
|
inline T |
<T : Any?> SavedState.write(block: SavedStateWriter.() -> T)Calls the specified function |
Cmn
|
Top-level functions
savedState
inline fun savedState(
initialState: Map<String, Any?> = emptyMap(),
builderAction: SavedStateWriter.() -> Unit = {}
): SavedState
Builds a new SavedState with the specified initialState, given as a Map of String keys and Any value.
Allows further modification of the state using the builderAction.
IMPORTANT: The SavedStateWriter passed as a receiver to the builderAction is valid only inside that function. Using it outside of the function may produce an unspecified behavior.
| Parameters | |
|---|---|
initialState: Map<String, Any?> = emptyMap() |
An initial map of key-value pairs to populate the state. Defaults to an empty map. |
builderAction: SavedStateWriter.() -> Unit = {} |
A lambda function with a |
| Returns | |
|---|---|
SavedState |
A |
savedState
inline fun savedState(initialState: Bundle, builderAction: SavedStateWriter.() -> Unit): Bundle
savedState
inline fun savedState(initialState: SavedState, builderAction: SavedStateWriter.() -> Unit = {}): SavedState
Builds a new SavedState with the specified initialState, given as a SavedState instance.
Allows further modification of the state using the builderAction.
IMPORTANT: The SavedStateWriter passed as a receiver to the builderAction is valid only inside that function. Using it outside of the function may produce an unspecified behavior.
| Parameters | |
|---|---|
initialState: SavedState |
An initial |
builderAction: SavedStateWriter.() -> Unit = {} |
A lambda function with a |
| Returns | |
|---|---|
SavedState |
A |
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 |
read
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.
IMPORTANT: The SavedStateReader passed as a receiver to the block is valid only inside that function. Using it outside of the function may produce an unspecified behavior.
| Parameters | |
|---|---|
block: SavedStateReader.() -> T |
A lambda function that performs read operations using the |
| Returns | |
|---|---|
T |
The result of the lambda function's execution. |
| See also | |
|---|---|
SavedStateReader |
|
SavedStateWriter |
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 |
write
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.
IMPORTANT: The SavedStateWriter passed as a receiver to the block is valid only inside that function. Using it outside of the function may produce an unspecified behavior.
| Parameters | |
|---|---|
block: SavedStateWriter.() -> T |
A lambda function that performs write operations using the |
| Returns | |
|---|---|
T |
The result of the lambda function's execution. |
| See also | |
|---|---|
SavedStateReader |
|
SavedStateWriter |