# StateStore

Artifact: [androidx.wear.protolayout:protolayout-expression-pipeline](https://developer.android.com/jetpack/androidx/releases/wear-protolayout) [View Source](https://cs.android.com/search?q=file:androidx/wear/protolayout/expression/pipeline/StateStore.java+class:androidx.wear.protolayout.expression.pipeline.StateStore) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/wear-protolayout#1.0.0)

*** ** * ** ***

<br />

```
class StateStore
```

<br />

*** ** * ** ***

State storage for ProtoLayout, which also supports sending callback when data items change.

Note that this class is \*\*not\*\* thread-safe. Since ProtoLayout inflation currently happens on the main thread, and because updates will eventually affect the main thread, this whole class must only be used from the UI thread.

## Summary

| ### Public functions |
|---|---|
| `java-static https://developer.android.com/reference/kotlin/androidx/wear/protolayout/expression/pipeline/StateStore` | `https://developer.android.com/reference/kotlin/androidx/wear/protolayout/expression/pipeline/StateStore#create(java.util.Map<androidx.wear.protolayout.expression.AppDataKey<?>,androidx.wear.protolayout.expression.DynamicDataBuilders.DynamicDataValue<?>>)( initialState: (https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-map/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-map/index.html<https://developer.android.com/reference/kotlin/androidx/wear/protolayout/expression/AppDataKey<*>!, https://developer.android.com/reference/kotlin/androidx/wear/protolayout/expression/DynamicDataBuilders.DynamicDataValue<*>!> )` Creates a `https://developer.android.com/reference/kotlin/androidx/wear/protolayout/expression/pipeline/StateStore`. |
| `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/wear/protolayout/expression/pipeline/StateStore#getMaxStateEntryCount()()` Returns the maximum number for state entries allowed for this `https://developer.android.com/reference/kotlin/androidx/wear/protolayout/expression/pipeline/StateStore`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `@https://developer.android.com/reference/kotlin/androidx/annotation/UiThread https://developer.android.com/reference/kotlin/androidx/wear/protolayout/expression/pipeline/StateStore#setAppStateEntryValues(java.util.Map<androidx.wear.protolayout.expression.AppDataKey<?>,androidx.wear.protolayout.expression.DynamicDataBuilders.DynamicDataValue<?>>)( newState: (https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-map/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-map/index.html<https://developer.android.com/reference/kotlin/androidx/wear/protolayout/expression/AppDataKey<*>!, https://developer.android.com/reference/kotlin/androidx/wear/protolayout/expression/DynamicDataBuilders.DynamicDataValue<*>!> )` Sets the given app state, replacing the current app state. |

## Public functions

### create

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/wear-protolayout#1.0.0)

```
java-static fun create(
    initialState: (Mutable)Map<AppDataKey<*>!, DynamicDataBuilders.DynamicDataValue<*>!>
): StateStore
```

Creates a `https://developer.android.com/reference/kotlin/androidx/wear/protolayout/expression/pipeline/StateStore`.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalStateException.html` | if number of initialState entries is greater than `https://developer.android.com/reference/kotlin/androidx/wear/protolayout/expression/pipeline/StateStore#getMaxStateEntryCount()`. |

### getMaxStateEntryCount

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/wear-protolayout#1.0.0)

```
java-static fun getMaxStateEntryCount(): Int
```

Returns the maximum number for state entries allowed for this `https://developer.android.com/reference/kotlin/androidx/wear/protolayout/expression/pipeline/StateStore`.

The ProtoLayout state model is not designed to handle large volumes of layout provided state. So we limit the number of state entries to keep the on-the-wire size and state store update times manageable.

### setAppStateEntryValues

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/wear-protolayout#1.0.0)

```
@UiThread
fun setAppStateEntryValues(
    newState: (Mutable)Map<AppDataKey<*>!, DynamicDataBuilders.DynamicDataValue<*>!>
): Unit
```

Sets the given app state, replacing the current app state.

Informs registered listeners of changed values, invalidates removed values.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalStateException.html` | if number of state entries is greater than `https://developer.android.com/reference/kotlin/androidx/wear/protolayout/expression/pipeline/StateStore#getMaxStateEntryCount()`. The state will not update and old state entries will stay in place. |