# 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)

*** ** * ** ***

Common/All
- Cmn

  ```
  @Serializable
  open class StateStoreKey<T : Any?>
  ```

*** ** * ** ***

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 : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> https://developer.android.com/reference/kotlin/androidx/appstate/statestore/StateStoreKey#StateStoreKey(kotlin.Any,androidx.appstate.statestore.StateStoreKey,kotlin.Function1)( defaultValue: T, autoClearKey: https://developer.android.com/reference/kotlin/androidx/appstate/statestore/StateStoreKey<*>?, shouldClearState: (https://developer.android.com/reference/kotlin/androidx/appstate/statestore/StateStore) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html )` | Cmn |

| ### Public properties |
|---|---|---|
| `https://developer.android.com/reference/kotlin/androidx/appstate/statestore/StateStoreKey<*>?` | `@https://kotlinlang.org/api/kotlinx.serialization/kotlinx-serialization-core/kotlinx.serialization/-transient/index.html https://developer.android.com/reference/kotlin/androidx/appstate/statestore/StateStoreKey#autoClearKey()` set this if you would like the state associated with this key to be automatically cleared from the `https://developer.android.com/reference/kotlin/androidx/appstate/statestore/StateStore` when `https://developer.android.com/reference/kotlin/androidx/appstate/statestore/StateStoreKey#shouldClearState()` is `true`. | Cmn |
| `T` | `https://developer.android.com/reference/kotlin/androidx/appstate/statestore/StateStoreKey#defaultValue()` an instance of the type `https://developer.android.com/reference/kotlin/androidx/appstate/statestore/StateStoreKey` that is associated with this key by default. | Cmn |
| `(https://developer.android.com/reference/kotlin/androidx/appstate/statestore/StateStore) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `@https://kotlinlang.org/api/kotlinx.serialization/kotlinx-serialization-core/kotlinx.serialization/-transient/index.html https://developer.android.com/reference/kotlin/androidx/appstate/statestore/StateStoreKey#shouldClearState()` the condition to determine whether the state should be cleared or not. | Cmn |

## Public constructors

### StateStoreKey

Cmn

```
<T : Any?> StateStoreKey(
    defaultValue: T,
    autoClearKey: StateStoreKey<*>? = null,
    shouldClearState: (StateStore) -> Boolean = { true }
)
```

| Parameters |
|---|---|
| `defaultValue: T` | an instance of the type `https://developer.android.com/reference/kotlin/androidx/appstate/statestore/StateStoreKey` that is associated with this key by default. |
| `autoClearKey: https://developer.android.com/reference/kotlin/androidx/appstate/statestore/StateStoreKey<*>? = null` | set this if you would like the state associated with this key to be automatically cleared from the `https://developer.android.com/reference/kotlin/androidx/appstate/statestore/StateStore` when `https://developer.android.com/reference/kotlin/androidx/appstate/statestore/StateStoreKey#shouldClearState()` is `true`. |
| `shouldClearState: (https://developer.android.com/reference/kotlin/androidx/appstate/statestore/StateStore) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html = { true }` | the condition to determine whether the state should be cleared or not. |

## Public properties

### autoClearKey

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

```
@Transient
val autoClearKey: StateStoreKey<*>?
```

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

### defaultValue

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

```
val defaultValue: T
```

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

### shouldClearState

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

```
@Transient
val shouldClearState: (StateStore) -> Boolean
```

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