# SavedState

Artifact: [androidx.savedstate:savedstate](https://developer.android.com/jetpack/androidx/releases/savedstate.md.txt) [View Source](https://cs.android.com/search?q=file:androidx/savedstate/SavedState.+class:androidx.savedstate.SavedState) Added in [1.6.0-alpha05](https://developer.android.com/jetpack/androidx/releases/savedstate.md.txt#1.6.0-alpha05)

*** ** * ** ***


```
public final class SavedState
```

<br />

*** ** * ** ***

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.

That means, the OS will give the chance for the process to keep the state of the application (normally using a serialization mechanism), and allow the app to restore its state later. That is commonly referred to as "state restoration".

A `SavedState` is required as the source input for a `SavedStateReader` or `SavedStateWriter`.

This class represents a container for persistable state data. It is designed to be platform-agnostic, allowing seamless state saving and restoration across different environments.

## Summary

| ### Extension functions |
|---|---|
| `final @NonNull T` | `<T extends Object> SavedStateKt.read( @NonNull SavedState receiver, @NonNull Function1<@NonNull SavedStateReader, @NonNull T> block )` Performs read operations on this `SavedState` using a `SavedStateReader`. |
| `final @NonNull T` | `<T extends Object> SavedStateKt.write( @NonNull SavedState receiver, @NonNull Function1<@NonNull SavedStateWriter, @NonNull T> block )` Performs write operations on this `SavedState` using a `SavedStateWriter`. |

## Extension functions

### SavedStateKt.read

Artifact: [androidx.savedstate:savedstate](https://developer.android.com/jetpack/androidx/releases/savedstate.md.txt) [View Source](https://cs.android.com/search?q=file:androidx/savedstate/SavedState.kt+function:read)

```
public final @NonNull T <T extends Object> SavedStateKt.read(
    @NonNull SavedState receiver,
    @NonNull Function1<@NonNull SavedStateReader, @NonNull T> block
)
```

Performs read operations on this `SavedState` using a `SavedStateReader`.

**IMPORTANT:** The `SavedStateReader` passed as a receiver to the `block` is valid only inside that function. Using it outside of the function may produce unspecified behavior.

| Parameters |
|---|---|
| `@NonNull Function1<@NonNull SavedStateReader, @NonNull T> block` | A lambda function that performs read operations using the `SavedStateReader`. |

| Returns |
|---|---|
| `@NonNull T` | The result of the `block` execution. |

| See also |
|---|---|
| `SavedStateReader` |   |
| `SavedStateWriter` |   |

### SavedStateKt.write

Artifact: [androidx.savedstate:savedstate](https://developer.android.com/jetpack/androidx/releases/savedstate.md.txt) [View Source](https://cs.android.com/search?q=file:androidx/savedstate/SavedState.kt+function:write)

```
public final @NonNull T <T extends Object> SavedStateKt.write(
    @NonNull SavedState receiver,
    @NonNull Function1<@NonNull SavedStateWriter, @NonNull T> block
)
```

Performs write operations on this `SavedState` using a `SavedStateWriter`.

**IMPORTANT:** The `SavedStateWriter` passed as a receiver to the `block` is valid only inside that function. Using it outside of the function may produce unspecified behavior.

| Parameters |
|---|---|
| `@NonNull Function1<@NonNull SavedStateWriter, @NonNull T> block` | A lambda function that performs write operations using the `SavedStateWriter`. |

| Returns |
|---|---|
| `@NonNull T` | The result of the `block` execution. |

| See also |
|---|---|
| `SavedStateReader` |   |
| `SavedStateWriter` |   |