public class PreferenceManager
extends Object

   ↳ androidx.preference.PreferenceManager

Used to help create Preference hierarchies from activities or XML.

In most cases, clients should use PreferenceFragmentCompat.addPreferencesFromResource(int).


Nested classes

interface PreferenceManager.OnDisplayPreferenceDialogListener

Interface definition for a class that will be called when a Preference requests to display a dialog. 

interface PreferenceManager.OnNavigateToScreenListener

Interface definition for a class that will be called when a PreferenceScreen requests navigation. 

interface PreferenceManager.OnPreferenceTreeClickListener

Interface definition for a callback to be invoked when a Preference in the hierarchy rooted at this PreferenceScreen is clicked. 

class PreferenceManager.PreferenceComparisonCallback

Callback class to be used by the RecyclerView.Adapter associated with the PreferenceScreen, used to determine when two Preference objects are semantically and visually the same. 

class PreferenceManager.SimplePreferenceComparisonCallback

A basic implementation of PreferenceManager.PreferenceComparisonCallback suitable for use with the default Preference classes. 



Public methods

PreferenceScreen createPreferenceScreen(Context context)
<T extends Preference> T findPreference(CharSequence key)

Finds a Preference with the given key.

Context getContext()

Returns the context.

static SharedPreferences getDefaultSharedPreferences(Context context)

Gets a SharedPreferences instance that points to the default file that is used by the preference framework in the given context.

PreferenceManager.OnDisplayPreferenceDialogListener getOnDisplayPreferenceDialogListener()
PreferenceManager.OnNavigateToScreenListener getOnNavigateToScreenListener()

Returns the PreferenceManager.OnNavigateToScreenListener, if one has been set.

PreferenceManager.OnPreferenceTreeClickListener getOnPreferenceTreeClickListener()
PreferenceManager.PreferenceComparisonCallback getPreferenceComparisonCallback()
PreferenceDataStore getPreferenceDataStore()

Returns the PreferenceDataStore associated with this manager or null if the default SharedPreferences are used instead.

PreferenceScreen getPreferenceScreen()

Returns the root of the preference hierarchy managed by this class.

SharedPreferences getSharedPreferences()

Gets a SharedPreferences instance that preferences managed by this will use.

int getSharedPreferencesMode()

Returns the current mode of the SharedPreferences file that preferences managed by this will use.

String getSharedPreferencesName()

Returns the current name of the SharedPreferences file that preferences managed by this will use.

boolean isStorageDefault()

Indicates if the storage location used internally by this class is the default provided by the hosting Context.

boolean isStorageDeviceProtected()

Indicates if the storage location used internally by this class is backed by device-protected storage.

static void setDefaultValues(Context context, String sharedPreferencesName, int sharedPreferencesMode, int resId, boolean readAgain)

Similar to setDefaultValues(Context, int, boolean) but allows the client to provide the filename and mode of the shared preferences file.

static void setDefaultValues(Context context, int resId, boolean readAgain)

Sets the default values from an XML preference file by reading the values defined by each Preference item's android:defaultValue attribute.

void setOnDisplayPreferenceDialogListener(PreferenceManager.OnDisplayPreferenceDialogListener onDisplayPreferenceDialogListener)
void setOnNavigateToScreenListener(PreferenceManager.OnNavigateToScreenListener listener)

Sets the callback to be invoked when a PreferenceScreen in the hi