# StateStoreKey

Artifact: [androidx.appstate.statestore:statestore](https://developer.android.com/jetpack/androidx/releases/appstate-statestore) [View Source](https://cs.android.com/search?q=file:androidx/appstate/statestore/StateStore.kt+class:androidx.appstate.statestore.StateStoreKey) Added in [1.0.0-alpha02](https://developer.android.com/jetpack/androidx/releases/appstate-statestore#1.0.0-alpha02)

*** ** * ** ***


```
@Serializable
public class StateStoreKey<T extends Object>
```

<br />

*** ** * ** ***

Open class that should be extended to define specific key-value types to be stored in the StateStore to ensure it is type safe.

The class T should be the value of the type that that should be retrieved and should also be @Serializable along with the extending class.

## Summary

| ### Public constructors |
|---|
| `<T extends https://developer.android.com/reference/java/lang/Object.html> https://developer.android.com/reference/androidx/appstate/statestore/StateStoreKey#StateStoreKey(kotlin.Any,androidx.appstate.statestore.StateStoreKey,kotlin.Function1)( @https://developer.android.com/reference/androidx/annotation/NonNull T defaultValue, https://developer.android.com/reference/androidx/appstate/statestore/StateStoreKey<@https://developer.android.com/reference/androidx/annotation/NonNull ?> autoClearKey, @https://developer.android.com/reference/androidx/annotation/NonNull Function1<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/appstate/statestore/StateStore, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Boolean.html> shouldClearState )` |

| ### Public methods |
|---|---|
| `final https://developer.android.com/reference/androidx/appstate/statestore/StateStoreKey<@https://developer.android.com/reference/androidx/annotation/NonNull ?>` | `https://developer.android.com/reference/androidx/appstate/statestore/StateStoreKey#getAutoClearKey()()` set this if you would like the state associated with this key to be automatically cleared from the `https://developer.android.com/reference/androidx/appstate/statestore/StateStore` when `https://developer.android.com/reference/androidx/appstate/statestore/StateStoreKey#shouldClearState()` is `true`. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull T` | `https://developer.android.com/reference/androidx/appstate/statestore/StateStoreKey#getDefaultValue()()` an instance of the type `https://developer.android.com/reference/androidx/appstate/statestore/StateStoreKey` that is associated with this key by default. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull Function1<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/appstate/statestore/StateStore, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Boolean.html>` | `https://developer.android.com/reference/androidx/appstate/statestore/StateStoreKey#getShouldClearState()()` the condition to determine whether the state should be cleared or not. |

## Public constructors

### StateStoreKey

```
public <T extends Object> StateStoreKey(
    @NonNull T defaultValue,
    StateStoreKey<@NonNull ?> autoClearKey,
    @NonNull Function1<@NonNull StateStore, @NonNull Boolean> shouldClearState
)
```

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull T defaultValue` | an instance of the type `https://developer.android.com/reference/androidx/appstate/statestore/StateStoreKey` that is associated with this key by default. |
| `https://developer.android.com/reference/androidx/appstate/statestore/StateStoreKey<@https://developer.android.com/reference/androidx/annotation/NonNull ?> autoClearKey` | set this if you would like the state associated with this key to be automatically cleared from the `https://developer.android.com/reference/androidx/appstate/statestore/StateStore` when `https://developer.android.com/reference/androidx/appstate/statestore/StateStoreKey#shouldClearState()` is `true`. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull Function1<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/appstate/statestore/StateStore, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Boolean.html> shouldClearState` | the condition to determine whether the state should be cleared or not. |

## Public methods

### getAutoClearKey

Added in [1.0.0-alpha02](https://developer.android.com/jetpack/androidx/releases/appstate-statestore#1.0.0-alpha02)

```
public final StateStoreKey<@NonNull ?> getAutoClearKey()
```

set this if you would like the state associated with this key to be automatically cleared from the `https://developer.android.com/reference/androidx/appstate/statestore/StateStore` when `https://developer.android.com/reference/androidx/appstate/statestore/StateStoreKey#shouldClearState()` is `true`.

### getDefaultValue

Added in [1.0.0-alpha02](https://developer.android.com/jetpack/androidx/releases/appstate-statestore#1.0.0-alpha02)

```
public final @NonNull T getDefaultValue()
```

an instance of the type `https://developer.android.com/reference/androidx/appstate/statestore/StateStoreKey` that is associated with this key by default.

### getShouldClearState

Added in [1.0.0-alpha02](https://developer.android.com/jetpack/androidx/releases/appstate-statestore#1.0.0-alpha02)

```
public final @NonNull Function1<@NonNull StateStore, @NonNull Boolean> getShouldClearState()
```

the condition to determine whether the state should be cleared or not.