# GlanceStateDefinition

# GlanceStateDefinition

Artifact:[androidx.glance:glance](https://developer.android.com/jetpack/androidx/releases/glance)  
[View Source](https://cs.android.com/search?q=file:androidx/glance/state/GlanceStateDefinition.kt+class:androidx.glance.state.GlanceStateDefinition)  
Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/glance#1.0.0)

<br />

```
interface GlanceStateDefinition<T : Any?>
```

<br />

Known direct subclasses  
[PreferencesGlanceStateDefinition](https://developer.android.com/reference/kotlin/androidx/glance/state/PreferencesGlanceStateDefinition)  

|-------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [PreferencesGlanceStateDefinition](https://developer.android.com/reference/kotlin/androidx/glance/state/PreferencesGlanceStateDefinition) | Base class helping the creation of a state using DataStore's[Preferences](https://developer.android.com/reference/kotlin/androidx/datastore/preferences/core/Preferences). |

*** ** * ** ***

Configuration definition for[GlanceState](https://developer.android.com/reference/kotlin/androidx/glance/state/GlanceState). This defines where the data is stored and how the underlying data store is created. Use a unique[GlanceStateDefinition](https://developer.android.com/reference/kotlin/androidx/glance/state/GlanceStateDefinition)to get a[GlanceState](https://developer.android.com/reference/kotlin/androidx/glance/state/GlanceState), once defined, the data should be updated using the state directly, this definition should not change.

## Summary

|                                             ### Public functions                                             |
|--------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `suspend `[DataStore](https://developer.android.com/reference/kotlin/androidx/datastore/core/DataStore)`<T>` | [getDataStore](https://developer.android.com/reference/kotlin/androidx/glance/state/GlanceStateDefinition#getDataStore(android.content.Context,kotlin.String))`(context: `[Context](https://developer.android.com/reference/android/content/Context.html)`, fileKey: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`)` Creates the underlying data store.                    |
| [File](https://developer.android.com/reference/java/io/File.html)                                            | [getLocation](https://developer.android.com/reference/kotlin/androidx/glance/state/GlanceStateDefinition#getLocation(android.content.Context,kotlin.String))`(context: `[Context](https://developer.android.com/reference/android/content/Context.html)`, fileKey: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`)` This file indicates the location of the persisted data. |

## Public functions

### getDataStore

```
suspend fun getDataStore(context: Context, fileKey: String): DataStore<T>
```

Creates the underlying data store.  

|                                          Parameters                                          |
|----------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `context: `[Context](https://developer.android.com/reference/android/content/Context.html)   | The context used to create locate the file directory                                                                                                              |
| `fileKey: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html) | The unique string key used to name and identify the data file corresponding to a remote UI. Each remote UI has a unique UI key, used to key the data for that UI. |

### getLocation

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

```
fun getLocation(context: Context, fileKey: String): File
```

This file indicates the location of the persisted data.  

|                                          Parameters                                          |
|----------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `context: `[Context](https://developer.android.com/reference/android/content/Context.html)   | The context used to create the file directory                                                                                                                     |
| `fileKey: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html) | The unique string key used to name and identify the data file corresponding to a remote UI. Each remote UI has a unique UI key, used to key the data for that UI. |