# SavedStateHandleSupport

Added in 2.5.0

*** ** * ** ***


```
public final class SavedStateHandleSupport
```

<br />

*** ** * ** ***

## Summary

| ### Public fields |
|---|---|
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/lifecycle/viewmodel/CreationExtras.Key<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/savedstate/SavedState>` | `https://developer.android.com/reference/androidx/lifecycle/SavedStateHandleSupport#DEFAULT_ARGS_KEY()` A `https://developer.android.com/reference/androidx/lifecycle/viewmodel/CreationExtras.Key` to retrieve the default `https://developer.android.com/reference/androidx/savedstate/SavedState` arguments to be passed to the `https://developer.android.com/reference/androidx/lifecycle/SavedStateHandle`. |
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/lifecycle/viewmodel/CreationExtras.Key<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/savedstate/SavedStateRegistryOwner>` | `https://developer.android.com/reference/androidx/lifecycle/SavedStateHandleSupport#SAVED_STATE_REGISTRY_OWNER_KEY()` A `https://developer.android.com/reference/androidx/lifecycle/viewmodel/CreationExtras.Key` to retrieve the `https://developer.android.com/reference/androidx/savedstate/SavedStateRegistryOwner` associated with the `https://developer.android.com/reference/androidx/lifecycle/ViewModel` being created. |
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/lifecycle/viewmodel/CreationExtras.Key<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/lifecycle/ViewModelStoreOwner>` | `https://developer.android.com/reference/androidx/lifecycle/SavedStateHandleSupport#VIEW_MODEL_STORE_OWNER_KEY()` A `https://developer.android.com/reference/androidx/lifecycle/viewmodel/CreationExtras.Key` to retrieve the `https://developer.android.com/reference/androidx/lifecycle/ViewModelStoreOwner` associated with the `https://developer.android.com/reference/androidx/lifecycle/ViewModel` being created. |

| ### Public methods |
|---|---|
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/lifecycle/SavedStateHandle` | `@https://developer.android.com/reference/androidx/annotation/MainThread https://developer.android.com/reference/androidx/lifecycle/SavedStateHandleSupport#(androidx.lifecycle.viewmodel.CreationExtras).createSavedStateHandle()(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/lifecycle/viewmodel/CreationExtras receiver)` Creates a `https://developer.android.com/reference/androidx/lifecycle/SavedStateHandle` for use in your `https://developer.android.com/reference/androidx/lifecycle/ViewModel`s. |
| `static final void` | `@https://developer.android.com/reference/androidx/annotation/MainThread <T extends https://developer.android.com/reference/androidx/savedstate/SavedStateRegistryOwner & https://developer.android.com/reference/androidx/lifecycle/ViewModelStoreOwner> https://developer.android.com/reference/androidx/lifecycle/SavedStateHandleSupport#(androidx.savedstate.SavedStateRegistryOwner).enableSavedStateHandles()( @https://developer.android.com/reference/androidx/annotation/NonNull T receiver )` Enables support for `https://developer.android.com/reference/androidx/lifecycle/SavedStateHandle` in a component. |

## Public fields

### DEFAULT_ARGS_KEY

Artifact: [androidx.lifecycle:lifecycle-viewmodel-savedstate](https://developer.android.com/jetpack/androidx/releases/lifecycle) [View Source](https://cs.android.com/search?q=file:androidx/lifecycle/SavedStateHandleSupport.kt+symbol:DEFAULT_ARGS_KEY) Added in [2.5.0](https://developer.android.com/jetpack/androidx/releases/lifecycle#2.5.0)

```
public static final @NonNull CreationExtras.Key<@NonNull SavedState> DEFAULT_ARGS_KEY
```

A `https://developer.android.com/reference/androidx/lifecycle/viewmodel/CreationExtras.Key` to retrieve the default `https://developer.android.com/reference/androidx/savedstate/SavedState` arguments to be passed to the `https://developer.android.com/reference/androidx/lifecycle/SavedStateHandle`.

### SAVED_STATE_REGISTRY_OWNER_KEY

Artifact: [androidx.lifecycle:lifecycle-viewmodel-savedstate](https://developer.android.com/jetpack/androidx/releases/lifecycle) [View Source](https://cs.android.com/search?q=file:androidx/lifecycle/SavedStateHandleSupport.kt+symbol:SAVED_STATE_REGISTRY_OWNER_KEY) Added in [2.5.0](https://developer.android.com/jetpack/androidx/releases/lifecycle#2.5.0)

```
public static final @NonNull CreationExtras.Key<@NonNull SavedStateRegistryOwner> SAVED_STATE_REGISTRY_OWNER_KEY
```

A `https://developer.android.com/reference/androidx/lifecycle/viewmodel/CreationExtras.Key` to retrieve the `https://developer.android.com/reference/androidx/savedstate/SavedStateRegistryOwner` associated with the `https://developer.android.com/reference/androidx/lifecycle/ViewModel` being created.

### VIEW_MODEL_STORE_OWNER_KEY

Artifact: [androidx.lifecycle:lifecycle-viewmodel-savedstate](https://developer.android.com/jetpack/androidx/releases/lifecycle) [View Source](https://cs.android.com/search?q=file:androidx/lifecycle/SavedStateHandleSupport.kt+symbol:VIEW_MODEL_STORE_OWNER_KEY) Added in [2.5.0](https://developer.android.com/jetpack/androidx/releases/lifecycle#2.5.0)

```
public static final @NonNull CreationExtras.Key<@NonNull ViewModelStoreOwner> VIEW_MODEL_STORE_OWNER_KEY
```

A `https://developer.android.com/reference/androidx/lifecycle/viewmodel/CreationExtras.Key` to retrieve the `https://developer.android.com/reference/androidx/lifecycle/ViewModelStoreOwner` associated with the `https://developer.android.com/reference/androidx/lifecycle/ViewModel` being created.

## Public methods

### createSavedStateHandle

Artifact: [androidx.lifecycle:lifecycle-viewmodel-savedstate](https://developer.android.com/jetpack/androidx/releases/lifecycle) [View Source](https://cs.android.com/search?q=file:androidx/lifecycle/SavedStateHandleSupport.kt+function:createSavedStateHandle) Added in [2.5.0](https://developer.android.com/jetpack/androidx/releases/lifecycle#2.5.0)

```
@MainThread
public static final @NonNull SavedStateHandle createSavedStateHandle(@NonNull CreationExtras receiver)
```

Creates a `https://developer.android.com/reference/androidx/lifecycle/SavedStateHandle` for use in your `https://developer.android.com/reference/androidx/lifecycle/ViewModel`s.

This function requires a call to `https://developer.android.com/reference/androidx/lifecycle/package-summary#(androidx.savedstate.SavedStateRegistryOwner).enableSavedStateHandles()` during component initialization. Modern Jetpack components (such as `ComponentActivity`, `Fragment`, and `NavBackStackEntry`) perform this call automatically.

The `https://developer.android.com/reference/androidx/lifecycle/viewmodel/CreationExtras` must contain `https://developer.android.com/reference/androidx/lifecycle/package-summary#SAVED_STATE_REGISTRY_OWNER_KEY()`, `https://developer.android.com/reference/androidx/lifecycle/package-summary#VIEW_MODEL_STORE_OWNER_KEY()`, and `https://developer.android.com/reference/androidx/lifecycle/ViewModelProvider.Companion#VIEW_MODEL_KEY()`.

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/lifecycle/SavedStateHandle` | new `https://developer.android.com/reference/androidx/lifecycle/SavedStateHandle` instance |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html` | If the `https://developer.android.com/reference/androidx/lifecycle/viewmodel/CreationExtras` is missing any of the required keys: `https://developer.android.com/reference/androidx/lifecycle/package-summary#VIEW_MODEL_STORE_OWNER_KEY()`, `https://developer.android.com/reference/androidx/lifecycle/package-summary#SAVED_STATE_REGISTRY_OWNER_KEY()`, or `https://developer.android.com/reference/androidx/lifecycle/ViewModelProvider.Companion#VIEW_MODEL_KEY()`. |

### enableSavedStateHandles

Artifact: [androidx.lifecycle:lifecycle-viewmodel-savedstate](https://developer.android.com/jetpack/androidx/releases/lifecycle) [View Source](https://cs.android.com/search?q=file:androidx/lifecycle/SavedStateHandleSupport.kt+function:enableSavedStateHandles) Added in [2.5.0](https://developer.android.com/jetpack/androidx/releases/lifecycle#2.5.0)

```
@MainThread
public static final void <T extends SavedStateRegistryOwner & ViewModelStoreOwner> enableSavedStateHandles(
    @NonNull T receiver
)
```

Enables support for `https://developer.android.com/reference/androidx/lifecycle/SavedStateHandle` in a component.

After calling this method, `https://developer.android.com/reference/androidx/lifecycle/package-summary#(androidx.lifecycle.viewmodel.CreationExtras).createSavedStateHandle()` can be invoked on `https://developer.android.com/reference/androidx/lifecycle/viewmodel/CreationExtras` containing the `https://developer.android.com/reference/androidx/savedstate/SavedStateRegistryOwner` and `https://developer.android.com/reference/androidx/lifecycle/ViewModelStoreOwner`.

This must be called while the component is in the `https://developer.android.com/reference/androidx/lifecycle/Lifecycle.State#INITIALIZED` or `https://developer.android.com/reference/androidx/lifecycle/Lifecycle.State#CREATED` state, and before requesting any `https://developer.android.com/reference/androidx/lifecycle/ViewModel` that requires a `https://developer.android.com/reference/androidx/lifecycle/SavedStateHandle`.