Preferences

abstract class Preferences(source)

Preferences and MutablePreferences are a lot like a generic Map and MutableMap keyed by the Preferences.Key class. These are intended for use with DataStore. Construct a DataStore instance using PreferenceDataStoreFactory.create.

Types

Link copied to clipboard
class Key<T>

Key for values stored in Preferences. Type T is the type of the value associated with the Key.

Link copied to clipboard
class Pair<T>

Key Value pairs for Preferences. Type T is the type of the value.

Functions

Link copied to clipboard
abstract fun asMap(): Map<Preferences.Key<*>, Any>

Retrieve a map of all key preference pairs. The returned map is unmodifiable, and attempts to mutate it will throw runtime exceptions.

Link copied to clipboard
abstract operator fun <T> contains(key: Preferences.Key<T>): Boolean

Returns true if this Preferences contains the specified key.

Link copied to clipboard
abstract operator fun <T> get(key: Preferences.Key<T>): T?

Get a preference with a key. If the key is not set, returns null.

Link copied to clipboard

Gets a mutable copy of Preferences which contains all the preferences in this Preferences. This can be used to update your preferences without building a new Preferences object from scratch in DataStore.updateData.

Link copied to clipboard

Gets a read-only copy of Preferences which contains all the preferences in this Preferences.

Inheritors

Link copied to clipboard