androidx.datastore.preferences.core
Classes
MutablePreferences |
Mutable version of Preferences. |
Preferences |
Preferences and MutablePreferences are a lot like a generic Map and MutableMap keyed by the Preferences. |
Top-level functions summary
Preferences.Key<Boolean> |
booleanPreferencesKey(name: String) Get a key for a Boolean preference. |
Preferences.Key<Double> |
doublePreferencesKey(name: String) Get a key for a Double preference. |
Preferences |
Get a new empty Preferences. |
Preferences.Key<Float> |
floatPreferencesKey(name: String) Get a key for a Float preference. |
Preferences.Key<Int> |
intPreferencesKey(name: String) Get a key for an Int preference. |
Preferences.Key<Long> |
longPreferencesKey(name: String) Get a key for an Long preference. |
MutablePreferences |
mutablePreferencesOf(vararg pairs: Preferences.Pair<*>) Construct a MutablePreferences object with a list of Preferences. |
Preferences |
preferencesOf(vararg pairs: Preferences.Pair<*>) Construct a Preferences object with a list of Preferences. |
Preferences.Key<String> |
stringPreferencesKey(name: String) Get a key for a String preference. |
Preferences.Key<Set<String>> |
stringSetPreferencesKey(name: String) Get a key for a String Set preference. |
Extension functions summary
For DataStore | |
suspend Preferences |
DataStore<Preferences>.edit(transform: suspend (MutablePreferences) -> Unit) Edit the value in DataStore transactionally in an atomic read-modify-write operation. |
Top-level functions
booleanPreferencesKey
@JvmName("booleanKey") fun booleanPreferencesKey(name: String): Preferences.Key<Boolean>
Get a key for a Boolean preference. You should not have multiple keys with the same name (for use with the same Preferences). Using overlapping keys with different types can result in ClassCastException.
Parameters | |
---|---|
name: String | the name of the preference |
Return | |
---|---|
the Preferences.Key | for name |
doublePreferencesKey
@JvmName("doubleKey") fun doublePreferencesKey(name: String): Preferences.Key<Double>
Get a key for a Double preference. You should not have multiple keys with the same name (for use with the same Preferences). Using overlapping keys with different types can result in ClassCastException.
Parameters | |
---|---|
name: String | the name of the preference |
Return | |
---|---|
the Preferences.Key | for name |
emptyPreferences
@JvmName("createEmpty") fun emptyPreferences(): Preferences
Get a new empty Preferences.
Return | |
---|---|
a new Preferences instance with no preferences set |
floatPreferencesKey
@JvmName("floatKey") fun floatPreferencesKey(name: String): Preferences.Key<Float>
Get a key for a Float preference. You should not have multiple keys with the same name (for use with the same Preferences). Using overlapping keys with different types can result in ClassCastException.
Parameters | |
---|---|
name: String | the name of the preference |
Return | |
---|---|
the Preferences.Key | for name |
intPreferencesKey
@JvmName("intKey") fun intPreferencesKey(name: String): Preferences.Key<Int>
Get a key for an Int preference. You should not have multiple keys with the same name (for use with the same Preferences). Using overlapping keys with different types can result in ClassCastException.
Parameters | |
---|---|
name: String | the name of the preference |
Return | |
---|---|
the Preferences.Key | for name |