T - Type of items within an array of which values should be persisted by ArrayPreference.public final class ArrayPreference<T> extends SharedPreference<T>
SharedPreference implementation that may be used to persist an array of values
via SharedPreferences.CollectionPreferenceSharedPreference.PreferenceChangeCallback<P>| Constructor and Description |
|---|
ArrayPreference(String key,
T defValue)
Creates a new instance of ArrayPreference with the specified key and defValue.
|
| Modifier and Type | Method and Description |
|---|---|
static <A> A |
getFromPreferences(android.content.SharedPreferences preferences,
String key,
Object defValue)
Obtains the array persisted within the given shared preferences for the
specified key.
|
protected T |
onGetFromPreferences(android.content.SharedPreferences preferences)
Invoked to retrieve the actual value of this preference from the given shared preferences.
|
protected boolean |
onPutIntoPreferences(android.content.SharedPreferences preferences)
Invoked to persist the actual value into the given shared preferences.
|
static boolean |
putIntoPreferences(android.content.SharedPreferences preferences,
String key,
Object value)
Persists the given array value for the specified key into the given
shared preferences.
|
createOnChangeListener, getDefaultValue, getKey, getValue, putIntoPreferences, updateValuepublic ArrayPreference(@NonNull
String key,
@Nullable
T defValue)
IllegalArgumentException - If the given defValue is not actually an array.SharedPreference.SharedPreference(String, Object)@CheckResult
protected boolean onPutIntoPreferences(@NonNull
android.content.SharedPreferences preferences)
SharedPreferenceonPutIntoPreferences in class SharedPreference<T>preferences - The instance of shared preferences into which should be the current value
of this preference persisted.True if put has been successful, false otherwise.putIntoPreferences(SharedPreferences, String, Object)@CheckResult
public static boolean putIntoPreferences(@NonNull
android.content.SharedPreferences preferences,
@NonNull
String key,
@Nullable
Object value)
preferences - The instance of shared preferences into which should be the given array persisted.key - The key for which should be the array mapped in the shared preferences.value - The desired array value to be persisted.True if put has been successful, false otherwise.IllegalArgumentException - If the given value is not actually an array.@Nullable protected T onGetFromPreferences(@NonNull android.content.SharedPreferences preferences)
SharedPreferenceonGetFromPreferences in class SharedPreference<T>preferences - The instance of shared preferences into which was the value of this preference
before saved.getFromPreferences(SharedPreferences, String, Object)@Nullable
public static <A> A getFromPreferences(@NonNull
android.content.SharedPreferences preferences,
@NonNull
String key,
@Nullable
Object defValue)
A - Type of the array to obtain.preferences - The instance of shared preferences where is the desired array persisted.key - The key for which is the desired array mapped in the shared preferences.defValue - Default array value to return in case when there is no array value persisted
for the specified key yet.ClassCastException - If value stored for the specified key does not represent an
array.IllegalArgumentException - If type of the requested array is not supported by this library.IllegalStateException - If the requested array was not stored by means of this library.