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

```
public final 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 methods |
|---|---|
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/wear/protolayout/expression/pipeline/StateStore` | `https://developer.android.com/reference/androidx/wear/protolayout/expression/pipeline/StateStore#create(java.util.Map<androidx.wear.protolayout.expression.AppDataKey<?>,androidx.wear.protolayout.expression.DynamicDataBuilders.DynamicDataValue<?>>)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/Map.html<https://developer.android.com/reference/androidx/wear/protolayout/expression/AppDataKey<@https://developer.android.com/reference/androidx/annotation/NonNull ?>, https://developer.android.com/reference/androidx/wear/protolayout/expression/DynamicDataBuilders.DynamicDataValue<@https://developer.android.com/reference/androidx/annotation/NonNull ?>> initialState )` Creates a `https://developer.android.com/reference/androidx/wear/protolayout/expression/pipeline/StateStore`. |
| `static int` | `https://developer.android.com/reference/androidx/wear/protolayout/expression/pipeline/StateStore#getMaxStateEntryCount()()` Returns the maximum number for state entries allowed for this `https://developer.android.com/reference/androidx/wear/protolayout/expression/pipeline/StateStore`. |
| `void` | `@https://developer.android.com/reference/androidx/annotation/UiThread https://developer.android.com/reference/androidx/wear/protolayout/expression/pipeline/StateStore#setAppStateEntryValues(java.util.Map<androidx.wear.protolayout.expression.AppDataKey<?>,androidx.wear.protolayout.expression.DynamicDataBuilders.DynamicDataValue<?>>)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/Map.html<https://developer.android.com/reference/androidx/wear/protolayout/expression/AppDataKey<@https://developer.android.com/reference/androidx/annotation/NonNull ?>, https://developer.android.com/reference/androidx/wear/protolayout/expression/DynamicDataBuilders.DynamicDataValue<@https://developer.android.com/reference/androidx/annotation/NonNull ?>> newState )` Sets the given app state, replacing the current app state. |

## Public methods

### create

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

```
public static @NonNull StateStore create(
    @NonNull Map<AppDataKey<@NonNull ?>, DynamicDataBuilders.DynamicDataValue<@NonNull ?>> initialState
)
```

Creates a `https://developer.android.com/reference/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/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)

```
public static int getMaxStateEntryCount()
```

Returns the maximum number for state entries allowed for this `https://developer.android.com/reference/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
public void setAppStateEntryValues(
    @NonNull Map<AppDataKey<@NonNull ?>, DynamicDataBuilders.DynamicDataValue<@NonNull ?>> newState
)
```

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/androidx/wear/protolayout/expression/pipeline/StateStore#getMaxStateEntryCount()`. The state will not update and old state entries will stay in place. |