Preferences

public abstract class Preferences

Known direct subclasses
MutablePreferences

Mutable version of Preferences.


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.

Summary

Nested types

Preferences.Key

Key for values stored in Preferences.

Preferences.Pair

Key Value pairs for Preferences.

Public methods

abstract @NonNull Map<@NonNull Preferences.Key<@NonNull ?>, @NonNull Object>

Retrieve a map of all key preference pairs.

abstract boolean
<T extends Object> contains(Preferences.Key<T> key)

Returns true if this Preferences contains the specified key.

abstract T
<T extends Object> get(Preferences.Key<T> key)

Get a preference with a key.

final @NonNull MutablePreferences

Gets a mutable copy of Preferences which contains all the preferences in this Preferences.

final @NonNull Preferences

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

Public methods

asMap

public abstract @NonNull Map<@NonNull Preferences.Key<@NonNull ?>, @NonNull ObjectasMap()

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

Returns
@NonNull Map<@NonNull Preferences.Key<@NonNull ?>, @NonNull Object>

a map containing all the preferences in this Preferences

contains

public abstract boolean <T extends Object> contains(Preferences.Key<T> key)

Returns true if this Preferences contains the specified key.

Parameters
Preferences.Key<T> key

the key to check for

get

public a