PreferenceDataStore
interfacePreferenceDataStore
android.preference.PreferenceDataStore |
A data store interface to be implemented and provided to the Preferences framework. This can be used to replace the default android.content.SharedPreferences
, if needed.
In most cases you want to use android.content.SharedPreferences
as it is automatically backed up and migrated to new devices. However, providing custom data store to preferences can be useful if your app stores its preferences in a local db, cloud or they are device specific like "Developer settings". It might be also useful when you want to use the preferences UI but the data are not supposed to be stored at all because they are valid per session only.
Once a put method is called it is full responsibility of the data store implementation to safely store the given values. Time expensive operations need to be done in the background to prevent from blocking the UI. You also need to have a plan on how to serialize the data in case the activity holding this object gets destroyed.
By default, all "put" methods throw UnsupportedOperationException
.
Summary
Public methods | |
---|---|
open Boolean |
getBoolean(key: String!, defValue: Boolean) Retrieve a boolean value from the data store. |
open Float |
Retrieve a float value from the data store. |
open Int |
Retrieve an int value from the data store. |
open Long |
Retrieve a long value from the data store. |
open String? |
Retrieve a String value from the data store. |
open MutableSet<String!>? |
getStringSet(key: String!, defValues: MutableSet<String!>?) Retrieve a set of String values from the data store. |
open Unit |
putBoolean(key: String!, value: Boolean) Set a boolean value to the data store. |
open Unit |
Set a float value to the data store. |
open Unit |
Set an int value to the data store. |
open Unit |
Set a long value to the data store. |
open Unit |
Set a String value to the data store. |
open Unit |
putStringSet(key: String!, values: MutableSet<String!>?) Set a set of String value to the data store. |
Public methods
getBoolean
open fungetBoolean(
key: String!,
defValue: Boolean
): Boolean
Deprecated: Deprecated in Java.
Retrieve a boolean value from the data store.
Parameters | |
---|---|
key |
String!: The name of the preference to retrieve. |
defValue |
Boolean: Value to return if this preference does not exist. |
See Also
getFloat
open fungetFloat(
key: String!,
defValue: Float
): Float
Deprecated: Deprecated in Java.
Retrieve a float value from the data store.
Parameters | |
---|---|
key |
String!: The name of the preference to retrieve. |
defValue |
Float: Value to return if this preference does not exist. |
See Also
getInt
open fungetInt(
key: String!,
defValue: Int
): Int
Deprecated: Deprecated in Java.
Retrieve an int value from the data store.
Parameters | |
---|---|
key |
String!: The name of the preference to retrieve. |
defValue |
Int: Value to return if this preference does not exist. |
See Also
getLong
open fungetLong(
key: String!,
defValue: Long
): Long
Deprecated: Deprecated in Java.
Retrieve a long value from the data store.
Parameters | |
---|---|
key |
String!: The name of the preference to retrieve. |
defValue |
Long: Value to return if this preference does not exist. |
See Also
getString
open fungetString(
key: String!,
defValue: String?
): String?
Deprecated: Deprecated in Java.
Retrieve a String value from the data store.
Parameters | |
---|---|
key |
String!: The name of the preference to retrieve. |
defValue |
String?: Value to return if this preference does not exist. This value may be null . |
Return | |
---|---|
String? |
This value may be null . |
See Also
getStringSet
open fungetStringSet(
key: String!,
defValues: MutableSet<String!>?
): MutableSet<String!>?
Deprecated: Deprecated in Java.
Retrieve a set of String values from the data store.
Parameters | |
---|---|
key |
String!: The name of the preference to retrieve. |
defValues |
MutableSet<String!>?: Values to return if this preference does not exist. This value may be null . |
Return | |
---|---|
MutableSet<String!>? |
This value may be null . |
See Also
putBoolean
open funputBoolean(
key: String!,
value: Boolean
): Unit
Deprecated: Deprecated in Java.
Set a boolean value to the data store.
Once the value is set the data store is responsible for holding it.
Parameters | |
---|---|
key |
String!: The name of the preference to modify. |
value |
Boolean: The new value for the preference. |
See Also
putFloat
open funputFloat(
key: String!,
value: Float
): Unit
Deprecated: Deprecated in Java.
Set a float value to the data store.
Once the value is set the data store is responsible for holding it.
Parameters | |
---|---|
key |
String!: The name of the preference to modify. |
value |
Float: The new value for the preference. |
See Also
putInt
open funputInt(
key: String!,
value: Int
): Unit
Deprecated: Deprecated in Java.
Set an int value to the data store.
Once the value is set the data store is responsible for holding it.
Parameters | |
---|---|
key |
String!: The name of the preference to modify. |
value |
Int: The new value for the preference. |
See Also
putLong
open funputLong(
key: String!,
value: Long
): Unit
Deprecated: Deprecated in Java.
Set a long value to the data store.
Once the value is set the data store is responsible for holding it.
Parameters | |
---|---|
key |
String!: The name of the preference to modify. |
value |
Long: The new value for the preference. |
See Also
putString
open funputString(
key: String!,
value: String?
): Unit
Deprecated: Deprecated in Java.
Set a String value to the data store.
Once the value is set the data store is responsible for holding it.
Parameters | |
---|---|
key |
String!: The name of the preference to modify. |
value |
String?: The new value for the preference. This value may be null . |
See Also
putStringSet
open funputStringSet(
key: String!,
values: MutableSet<String!>?
): Unit
Deprecated: Deprecated in Java.
Set a set of String value to the data store.
Once the value is set the data store is responsible for holding it.
Parameters | |
---|---|
key |
String!: The name of the preference to modify. |
values |
MutableSet<String!>?: The set of new values for the preference. This value may be null . |
See Also