PreferenceDataStore
public
interface
PreferenceDataStore
android.preference.PreferenceDataStore |
A data store interface to be implemented and provided to the Preferences framework. This can be
used to replace the default SharedPreferences
, if needed.
In most cases you want to use 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 | |
---|---|
default
boolean
|
getBoolean(String key, boolean defValue)
Retrieve a boolean value from the data store. |
default
float
|
getFloat(String key, float defValue)
Retrieve a float value from the data store. |
default
int
|
getInt(String key, int defValue)
Retrieve an int value from the data store. |
default
long
|
getLong(String key, long defValue)
Retrieve a long value from the data store. |
default
String
|
getString(String key, String defValue)
Retrieve a String value from the data store. |
default
Set<String>
|
getStringSet(String key, Set<String> defValues)
Retrieve a set of String values from the data store. |
default
void
|
putBoolean(String key, boolean value)
Set a boolean value to the data store. |
default
void
|
putFloat(String key, float value)
Set a float value to the data store. |
default
void
|
putInt(String key, int value)
Set an int value to the data store. |
default
void
|
putLong(String key, long value)
Set a long value to the data store. |
default
void
|
putString(String key, String value)
Set a String value to the data store. |
default
void
|
putStringSet(String key, Set<String> values)
Set a set of String value to the data store. |
Public methods
getBoolean
boolean getBoolean (String key, boolean defValue)
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. |
Returns | |
---|---|
boolean |
See also:
getFloat
float getFloat (String key, float defValue)
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. |
Returns | |
---|---|
float |
See also:
getInt
int getInt (String key, int defValue)
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. |
Returns | |
---|---|
int |
See also:
getLong
long getLong (String key, long defValue)
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. |
Returns | |
---|---|
long |
See also:
getString
String getString (String key, String defValue)
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 |
Returns | |
---|---|
String |
This value may be |
See also:
getStringSet
Set<String> getStringSet (String key, Set<String> defValues)
Retrieve a set of String values from the data store.
Parameters | |
---|---|
key |
String : The name of the preference to retrieve. |
defValues |
Set : Values to return if this preference does not exist.This value may be |
Returns | |
---|---|
Set<String> |
This value may be |
See also:
putBoolean
void putBoolean (String key, boolean value)
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
void putFloat (String key, float value)
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
void putInt (String key, int value)
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
void putLong (String key, long value)
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
void putString (String key, String value)
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 |
See also:
putStringSet
void putStringSet (String key, Set<String> values)
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 |
Set : The set of new values for the preference.This value may be |
See also:
Interfaces
Classes
- CheckBoxPreference
- DialogPreference
- EditTextPreference
- ListPreference
- MultiSelectListPreference
- Preference
- Preference.BaseSavedState
- PreferenceActivity
- PreferenceActivity.Header
- PreferenceCategory
- PreferenceFragment
- PreferenceGroup
- PreferenceManager
- PreferenceScreen
- RingtonePreference
- SwitchPreference
- TwoStatePreference