public interface PersistToDataStore<T extends Object>


Marks a StateStoreKey to be persisted to DataStore.

Keys implementing this interface will have their state automatically saved and restored if the StateStore calls the syncToDataStore function. The key provides the name its value is stored under and the KSerializer for the value:

@Serializable
object
SettingsKey : StateStoreKey<Settings>(Settings()), PersistToDataStore<Settings> {
override val name = "settings"
override val serializer = Settings.serializer()
}
Parameters
<T extends Object>

the type of the value held by the implementing StateStoreKey

Summary

Public methods

abstract @NonNull String

The name the value is stored under.

abstract @NonNull KSerializer<@NonNull T>

The serializer used to save and restore the value of the implementing StateStoreKey.

Public methods

getName

Added in 1.0.0-alpha03
abstract @NonNull String getName()

The name the value is stored under.

It must be unique among the keys synced to the same DataStore and must not change between versions of the app, since persisted data is looked up by it.

getSerializer

Added in 1.0.0-alpha03
abstract @NonNull KSerializer<@NonNull T> getSerializer()

The serializer used to save and restore the value of the implementing StateStoreKey.