# PreferenceManager

Artifact: [androidx.preference:preference](https://developer.android.com/jetpack/androidx/releases/preference) [View Source](https://cs.android.com/search?q=file:androidx/preference/PreferenceManager.java+class:androidx.preference.PreferenceManager) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/preference#1.0.0)

*** ** * ** ***


```
public class PreferenceManager
```

<br />

*** ** * ** ***

Used to help create `https://developer.android.com/reference/androidx/preference/Preference` hierarchies from activities or XML.

In most cases, clients should use `https://developer.android.com/reference/androidx/preference/PreferenceFragmentCompat#addPreferencesFromResource(int)`.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/preference/PreferenceFragmentCompat` |   |

## Summary

| ### Nested types |
|---|
| `public interface https://developer.android.com/reference/androidx/preference/PreferenceManager.OnDisplayPreferenceDialogListener` Interface definition for a class that will be called when a `https://developer.android.com/reference/androidx/preference/Preference` requests to display a dialog. |
| `public interface https://developer.android.com/reference/androidx/preference/PreferenceManager.OnNavigateToScreenListener` Interface definition for a class that will be called when a `https://developer.android.com/reference/androidx/preference/PreferenceScreen` requests navigation. |
| `public interface https://developer.android.com/reference/androidx/preference/PreferenceManager.OnPreferenceTreeClickListener` Interface definition for a callback to be invoked when a `https://developer.android.com/reference/androidx/preference/Preference` in the hierarchy rooted at this `https://developer.android.com/reference/androidx/preference/PreferenceScreen` is clicked. |
| `public abstract class https://developer.android.com/reference/androidx/preference/PreferenceManager.PreferenceComparisonCallback` Callback class to be used by the `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.Adapter` associated with the `https://developer.android.com/reference/androidx/preference/PreferenceScreen`, used to determine when two `https://developer.android.com/reference/androidx/preference/Preference` objects are semantically and visually the same. |
| `public class https://developer.android.com/reference/androidx/preference/PreferenceManager.SimplePreferenceComparisonCallback extends https://developer.android.com/reference/androidx/preference/PreferenceManager.PreferenceComparisonCallback` A basic implementation of `https://developer.android.com/reference/androidx/preference/PreferenceManager.PreferenceComparisonCallback` suitable for use with the default `https://developer.android.com/reference/androidx/preference/Preference` classes. |

| ### Constants |
|---|---|
| `static final https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/preference/PreferenceManager#KEY_HAS_SET_DEFAULT_VALUES() = "_has_set_default_values"` |

| ### Public methods |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/preference/PreferenceScreen` | `https://developer.android.com/reference/androidx/preference/PreferenceManager#createPreferenceScreen(android.content.Context)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/content/Context.html context)` |
| `@https://developer.android.com/reference/androidx/annotation/Nullable T` | `<T extends https://developer.android.com/reference/androidx/preference/Preference> https://developer.android.com/reference/androidx/preference/PreferenceManager#findPreference(java.lang.CharSequence)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/CharSequence.html key)` Finds a `https://developer.android.com/reference/androidx/preference/Preference` with the given key. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/content/Context.html` | `https://developer.android.com/reference/androidx/preference/PreferenceManager#getContext()()` Returns the context. |
| `static https://developer.android.com/reference/android/content/SharedPreferences.html` | `https://developer.android.com/reference/androidx/preference/PreferenceManager#getDefaultSharedPreferences(android.content.Context)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/content/Context.html context)` Gets a `https://developer.android.com/reference/android/content/SharedPreferences.html` instance that points to the default file that is used by the preference framework in the given context. |
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/preference/PreferenceManager.OnDisplayPreferenceDialogListener` | `https://developer.android.com/reference/androidx/preference/PreferenceManager#getOnDisplayPreferenceDialogListener()()` |
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/preference/PreferenceManager.OnNavigateToScreenListener` | `https://developer.android.com/reference/androidx/preference/PreferenceManager#getOnNavigateToScreenListener()()` Returns the `https://developer.android.com/reference/androidx/preference/PreferenceManager.OnNavigateToScreenListener`, if one has been set. |
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/preference/PreferenceManager.OnPreferenceTreeClickListener` | `https://developer.android.com/reference/androidx/preference/PreferenceManager#getOnPreferenceTreeClickListener()()` |
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/preference/PreferenceManager.PreferenceComparisonCallback` | `https://developer.android.com/reference/androidx/preference/PreferenceManager#getPreferenceComparisonCallback()()` |
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/preference/PreferenceDataStore` | `https://developer.android.com/reference/androidx/preference/PreferenceManager#getPreferenceDataStore()()` Returns the `https://developer.android.com/reference/androidx/preference/PreferenceDataStore` associated with this manager or `null` if the default `https://developer.android.com/reference/android/content/SharedPreferences.html` are used instead. |
| `https://developer.android.com/reference/androidx/preference/PreferenceScreen` | `https://developer.android.com/reference/androidx/preference/PreferenceManager#getPreferenceScreen()()` Returns the root of the preference hierarchy managed by this class. |
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/android/content/SharedPreferences.html` | `https://developer.android.com/reference/androidx/preference/PreferenceManager#getSharedPreferences()()` Gets a `https://developer.android.com/reference/android/content/SharedPreferences.html` instance that preferences managed by this will use. |
| `int` | `https://developer.android.com/reference/androidx/preference/PreferenceManager#getSharedPreferencesMode()()` Returns the current mode of the `https://developer.android.com/reference/android/content/SharedPreferences.html` file that preferences managed by this will use. |
| `https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/preference/PreferenceManager#getSharedPreferencesName()()` Returns the current name of the `https://developer.android.com/reference/android/content/SharedPreferences.html` file that preferences managed by this will use. |
| `boolean` | `https://developer.android.com/reference/androidx/preference/PreferenceManager#isStorageDefault()()` Indicates if the storage location used internally by this class is the default provided by the hosting `https://developer.android.com/reference/android/content/Context.html`. |
| `boolean` | `https://developer.android.com/reference/androidx/preference/PreferenceManager#isStorageDeviceProtected()()` Indicates if the storage location used internally by this class is backed by device-protected storage. |
| `static void` | `https://developer.android.com/reference/androidx/preference/PreferenceManager#setDefaultValues(android.content.Context,int,boolean)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/content/Context.html context, int resId, boolean readAgain)` Sets the default values from an XML preference file by reading the values defined by each `https://developer.android.com/reference/androidx/preference/Preference` item's `android:defaultValue` attribute. |
| `static void` | `https://developer.android.com/reference/androidx/preference/PreferenceManager#setDefaultValues(android.content.Context,java.lang.String,int,int,boolean)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/content/Context.html context, https://developer.android.com/reference/java/lang/String.html sharedPreferencesName, int sharedPreferencesMode, int resId, boolean readAgain )` Similar to `https://developer.android.com/reference/androidx/preference/PreferenceManager#setDefaultValues(android.content.Context,int,boolean)` but allows the client to provide the filename and mode of the shared preferences file. |
| `void` | `https://developer.android.com/reference/androidx/preference/PreferenceManager#setOnDisplayPreferenceDialogListener(androidx.preference.PreferenceManager.OnDisplayPreferenceDialogListener)( @https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/preference/PreferenceManager.OnDisplayPreferenceDialogListener onDisplayPreferenceDialogListener )` |
| `void` | `https://developer.android.com/reference/androidx/preference/PreferenceManager#setOnNavigateToScreenListener(androidx.preference.PreferenceManager.OnNavigateToScreenListener)( @https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/preference/PreferenceManager.OnNavigateToScreenListener listener )` Sets the callback to be invoked when a `https://developer.android.com/reference/androidx/preference/PreferenceScreen` in the hierarchy rooted at this `https://developer.android.com/reference/androidx/preference/PreferenceManager` is clicked. |
| `void` | `https://developer.android.com/reference/androidx/preference/PreferenceManager#setOnPreferenceTreeClickListener(androidx.preference.PreferenceManager.OnPreferenceTreeClickListener)( @https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/preference/PreferenceManager.OnPreferenceTreeClickListener listener )` Sets the callback to be invoked when a `https://developer.android.com/reference/androidx/preference/Preference` in the hierarchy rooted at this `https://developer.android.com/reference/androidx/preference/PreferenceManager` is clicked. |
| `void` | `https://developer.android.com/reference/androidx/preference/PreferenceManager#setPreferenceComparisonCallback(androidx.preference.PreferenceManager.PreferenceComparisonCallback)( @https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/preference/PreferenceManager.PreferenceComparisonCallback preferenceComparisonCallback )` |
| `void` | `https://developer.android.com/reference/androidx/preference/PreferenceManager#setPreferenceDataStore(androidx.preference.PreferenceDataStore)(@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/preference/PreferenceDataStore dataStore)` Sets a `https://developer.android.com/reference/androidx/preference/PreferenceDataStore` to be used by all preferences associated with this manager that don't have a custom `https://developer.android.com/reference/androidx/preference/PreferenceDataStore` assigned via `https://developer.android.com/reference/androidx/preference/Preference#setPreferenceDataStore(androidx.preference.PreferenceDataStore)`. |
| `boolean` | `https://developer.android.com/reference/androidx/preference/PreferenceManager#setPreferences(androidx.preference.PreferenceScreen)(https://developer.android.com/reference/androidx/preference/PreferenceScreen preferenceScreen)` Sets the root of the preference hierarchy. |
| `void` | `https://developer.android.com/reference/androidx/preference/PreferenceManager#setSharedPreferencesMode(int)(int sharedPreferencesMode)` Sets the mode of the `https://developer.android.com/reference/android/content/SharedPreferences.html` file that preferences managed by this will use. |
| `void` | `https://developer.android.com/reference/androidx/preference/PreferenceManager#setSharedPreferencesName(java.lang.String)(https://developer.android.com/reference/java/lang/String.html sharedPreferencesName)` Sets the name of the `https://developer.android.com/reference/android/content/SharedPreferences.html` file that preferences managed by this will use. |
| `void` | `https://developer.android.com/reference/androidx/preference/PreferenceManager#setStorageDefault()()` Sets the storage location used internally by this class to be the default provided by the hosting `https://developer.android.com/reference/android/content/Context.html`. |
| `void` | `https://developer.android.com/reference/androidx/preference/PreferenceManager#setStorageDeviceProtected()()` Explicitly set the storage location used internally by this class to be device-protected storage. |
| `void` | `https://developer.android.com/reference/androidx/preference/PreferenceManager#showDialog(androidx.preference.Preference)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/preference/Preference preference)` Called when a preference requests that a dialog be shown to complete a user interaction. |

## Constants

### KEY_HAS_SET_DEFAULT_VALUES

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/preference#1.0.0)

```
public static final String KEY_HAS_SET_DEFAULT_VALUES = "_has_set_default_values"
```

## Public methods

### createPreferenceScreen

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/preference#1.0.0)

```
public @NonNull PreferenceScreen createPreferenceScreen(@NonNull Context context)
```

### findPreference

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/preference#1.1.0)

```
public @Nullable T <T extends Preference> findPreference(@NonNull CharSequence key)
```

Finds a `https://developer.android.com/reference/androidx/preference/Preference` with the given key. Returns `null` if no `https://developer.android.com/reference/androidx/preference/Preference` could be found with the given key.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/CharSequence.html key` | The key of the `https://developer.android.com/reference/androidx/preference/Preference` to retrieve |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/Nullable T` | The `https://developer.android.com/reference/androidx/preference/Preference` with the key, or `null` |

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/preference/PreferenceGroup#findPreference(java.lang.CharSequence)` |   |

### getContext

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/preference#1.0.0)

```
public @NonNull Context getContext()
```

Returns the context.

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/content/Context.html` | The `https://developer.android.com/reference/android/content/Context.html` |

### getDefaultSharedPreferences

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/preference#1.0.0)

```
public static SharedPreferences getDefaultSharedPreferences(@NonNull Context context)
```

Gets a `https://developer.android.com/reference/android/content/SharedPreferences.html` instance that points to the default file that is used by the preference framework in the given context.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/content/Context.html context` | The context of the preferences whose values are wanted |

| Returns |
|---|---|
| `https://developer.android.com/reference/android/content/SharedPreferences.html` | A `https://developer.android.com/reference/android/content/SharedPreferences.html` instance that can be used to retrieve and listen to values of the preferences |

### getOnDisplayPreferenceDialogListener

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/preference#1.0.0)

```
public @Nullable PreferenceManager.OnDisplayPreferenceDialogListener getOnDisplayPreferenceDialogListener()
```

### getOnNavigateToScreenListener

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/preference#1.0.0)

```
public @Nullable PreferenceManager.OnNavigateToScreenListener getOnNavigateToScreenListener()
```

Returns the `https://developer.android.com/reference/androidx/preference/PreferenceManager.OnNavigateToScreenListener`, if one has been set.

### getOnPreferenceTreeClickListener

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/preference#1.0.0)

```
public @Nullable PreferenceManager.OnPreferenceTreeClickListener getOnPreferenceTreeClickListener()
```

### getPreferenceComparisonCallback

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/preference#1.0.0)

```
public @Nullable PreferenceManager.PreferenceComparisonCallback getPreferenceComparisonCallback()
```

### getPreferenceDataStore

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/preference#1.0.0)

```
public @Nullable PreferenceDataStore getPreferenceDataStore()
```

Returns the `https://developer.android.com/reference/androidx/preference/PreferenceDataStore` associated with this manager or `null` if the default `https://developer.android.com/reference/android/content/SharedPreferences.html` are used instead.

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/preference/PreferenceDataStore` | The `https://developer.android.com/reference/androidx/preference/PreferenceDataStore` associated with this manager or `null` if none |

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/preference/PreferenceManager#setPreferenceDataStore(androidx.preference.PreferenceDataStore)` |   |

### getPreferenceScreen

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/preference#1.0.0)

```
public PreferenceScreen getPreferenceScreen()
```

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

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/preference/PreferenceScreen` | The `https://developer.android.com/reference/androidx/preference/PreferenceScreen` object that is at the root of the hierarchy |

### getSharedPreferences

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/preference#1.0.0)

```
public @Nullable SharedPreferences getSharedPreferences()
```

Gets a `https://developer.android.com/reference/android/content/SharedPreferences.html` instance that preferences managed by this will use.

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/android/content/SharedPreferences.html` | A `https://developer.android.com/reference/android/content/SharedPreferences.html` instance pointing to the file that contain the values of preferences that are managed by this PreferenceManager. If a `https://developer.android.com/reference/androidx/preference/PreferenceDataStore` has been set, this method returns `null`. |

### getSharedPreferencesMode

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/preference#1.0.0)

```
public int getSharedPreferencesMode()
```

Returns the current mode of the `https://developer.android.com/reference/android/content/SharedPreferences.html` file that preferences managed by this will use.

| Returns |
|---|---|
| `int` | The mode that can be passed to `https://developer.android.com/reference/android/content/Context.html#getSharedPreferences(java.lang.String, int)` |

| See also |
|---|---|
| `https://developer.android.com/reference/android/content/Context.html#getSharedPreferences(java.lang.String, int)` |   |

### getSharedPreferencesName

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/preference#1.0.0)

```
public String getSharedPreferencesName()
```

Returns the current name of the `https://developer.android.com/reference/android/content/SharedPreferences.html` file that preferences managed by this will use.

| Returns |
|---|---|
| `https://developer.android.com/reference/java/lang/String.html` | The name that can be passed to `https://developer.android.com/reference/android/content/Context.html#getSharedPreferences(java.lang.String, int)` |

| See also |
|---|---|
| `https://developer.android.com/reference/android/content/Context.html#getSharedPreferences(java.lang.String, int)` |   |

### isStorageDefault

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/preference#1.0.0)

```
public boolean isStorageDefault()
```

Indicates if the storage location used internally by this class is the default provided by the hosting `https://developer.android.com/reference/android/content/Context.html`.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/preference/PreferenceManager#setStorageDefault()` |   |
| `https://developer.android.com/reference/androidx/preference/PreferenceManager#setStorageDeviceProtected()` |   |

### isStorageDeviceProtected

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/preference#1.0.0)

```
public boolean isStorageDeviceProtected()
```

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

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/preference/PreferenceManager#setStorageDefault()` |   |
| `https://developer.android.com/reference/androidx/preference/PreferenceManager#setStorageDeviceProtected()` |   |

### setDefaultValues

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/preference#1.0.0)

```
public static void setDefaultValues(@NonNull Context context, int resId, boolean readAgain)
```

Sets the default values from an XML preference file by reading the values defined by each `https://developer.android.com/reference/androidx/preference/Preference` item's `android:defaultValue` attribute. This should be called by the application's main activity.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/content/Context.html context` | The context of the shared preferences |
| `int resId` | The resource ID of the preference XML file |
| `boolean readAgain` | Whether to re-read the default values. If false, this method sets the default values only if this method has never been called in the past (or if the `https://developer.android.com/reference/androidx/preference/PreferenceManager#KEY_HAS_SET_DEFAULT_VALUES()` in the default value shared preferences file is false). To attempt to set the default values again bypassing this check, set `readAgain` to true. Note: this will NOT reset preferences back to their default values. For that functionality, use `https://developer.android.com/reference/androidx/preference/PreferenceManager#getDefaultSharedPreferences(android.content.Context)` and clear it followed by a call to this method with this parameter set to true. |

### setDefaultValues

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/preference#1.0.0)

```
public static void setDefaultValues(
    @NonNull Context context,
    String sharedPreferencesName,
    int sharedPreferencesMode,
    int resId,
    boolean readAgain
)
```

Similar to `https://developer.android.com/reference/androidx/preference/PreferenceManager#setDefaultValues(android.content.Context,int,boolean)` but allows the client to provide the filename and mode of the shared preferences file.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/content/Context.html context` | The context of the shared preferences |
| `https://developer.android.com/reference/java/lang/String.html sharedPreferencesName` | A custom name for the shared preferences file |
| `int sharedPreferencesMode` | The file creation mode for the shared preferences file, such as `https://developer.android.com/reference/android/content/Context.html#MODE_PRIVATE` or `https://developer.android.com/reference/android/content/Context.html#MODE_PRIVATE`. |
| `int resId` | The resource ID of the preference XML file |
| `boolean readAgain` | Whether to re-read the default values. If false, this method will set the default values only if this method has never been called in the past (or if the `https://developer.android.com/reference/androidx/preference/PreferenceManager#KEY_HAS_SET_DEFAULT_VALUES()` in the default value shared preferences file is false). To attempt to set the default values again bypassing this check, set ` readAgain` to true. Note: this will NOT reset preferences back to their default values. For that functionality, use `https://developer.android.com/reference/androidx/preference/PreferenceManager#getDefaultSharedPreferences(android.content.Context)` and clear it followed by a call to this method with this parameter set to true. |

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/preference/PreferenceManager#setDefaultValues(android.content.Context,int,boolean)` |   |
| `https://developer.android.com/reference/androidx/preference/PreferenceManager#setSharedPreferencesName(java.lang.String)` |   |
| `https://developer.android.com/reference/androidx/preference/PreferenceManager#setSharedPreferencesMode(int)` |   |

### setOnDisplayPreferenceDialogListener

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/preference#1.0.0)

```
public void setOnDisplayPreferenceDialogListener(
    @Nullable PreferenceManager.OnDisplayPreferenceDialogListener onDisplayPreferenceDialogListener
)
```

### setOnNavigateToScreenListener

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/preference#1.0.0)

```
public void setOnNavigateToScreenListener(
    @Nullable PreferenceManager.OnNavigateToScreenListener listener
)
```

Sets the callback to be invoked when a `https://developer.android.com/reference/androidx/preference/PreferenceScreen` in the hierarchy rooted at this `https://developer.android.com/reference/androidx/preference/PreferenceManager` is clicked.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/preference/PreferenceManager.OnNavigateToScreenListener listener` | The callback to be invoked |

### setOnPreferenceTreeClickListener

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/preference#1.0.0)

```
public void setOnPreferenceTreeClickListener(
    @Nullable PreferenceManager.OnPreferenceTreeClickListener listener
)
```

Sets the callback to be invoked when a `https://developer.android.com/reference/androidx/preference/Preference` in the hierarchy rooted at this `https://developer.android.com/reference/androidx/preference/PreferenceManager` is clicked.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/preference/PreferenceManager.OnPreferenceTreeClickListener listener` | The callback to be invoked |

### setPreferenceComparisonCallback

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/preference#1.0.0)

```
public void setPreferenceComparisonCallback(
    @Nullable PreferenceManager.PreferenceComparisonCallback preferenceComparisonCallback
)
```

### setPreferenceDataStore

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/preference#1.0.0)

```
public void setPreferenceDataStore(@Nullable PreferenceDataStore dataStore)
```

Sets a `https://developer.android.com/reference/androidx/preference/PreferenceDataStore` to be used by all preferences associated with this manager that don't have a custom `https://developer.android.com/reference/androidx/preference/PreferenceDataStore` assigned via `https://developer.android.com/reference/androidx/preference/Preference#setPreferenceDataStore(androidx.preference.PreferenceDataStore)`. Also if the data store is set, the child preferences won't use `https://developer.android.com/reference/android/content/SharedPreferences.html` as long as they are assigned to this manager.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/preference/PreferenceDataStore dataStore` | The `https://developer.android.com/reference/androidx/preference/PreferenceDataStore` to be used by this manager |

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/preference/Preference#setPreferenceDataStore(androidx.preference.PreferenceDataStore)` |   |

### setPreferences

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/preference#1.0.0)

```
public boolean setPreferences(PreferenceScreen preferenceScreen)
```

Sets the root of the preference hierarchy.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/preference/PreferenceScreen preferenceScreen` | The root `https://developer.android.com/reference/androidx/preference/PreferenceScreen` of the preference hierarchy |

| Returns |
|---|---|
| `boolean` | Whether the `https://developer.android.com/reference/androidx/preference/PreferenceScreen` given is different than the previous |

### setSharedPreferencesMode

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/preference#1.0.0)

```
public void setSharedPreferencesMode(int sharedPreferencesMode)
```

Sets the mode of the `https://developer.android.com/reference/android/content/SharedPreferences.html` file that preferences managed by this will use.

| Parameters |
|---|---|
| `int sharedPreferencesMode` | The mode of the SharedPreferences file |

| See also |
|---|---|
| `https://developer.android.com/reference/android/content/Context.html#getSharedPreferences(java.lang.String, int)` |   |

### setSharedPreferencesName

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/preference#1.0.0)

```
public void setSharedPreferencesName(String sharedPreferencesName)
```

Sets the name of the `https://developer.android.com/reference/android/content/SharedPreferences.html` file that preferences managed by this will use.

If custom `https://developer.android.com/reference/androidx/preference/PreferenceDataStore` is set, this won't override its usage.

| Parameters |
|---|---|
| `https://developer.android.com/reference/java/lang/String.html sharedPreferencesName` | The name of the SharedPreferences file |

| See also |
|---|---|
| `https://developer.android.com/reference/android/content/Context.html#getSharedPreferences(java.lang.String, int)` |   |
| `https://developer.android.com/reference/androidx/preference/PreferenceManager#setPreferenceDataStore(androidx.preference.PreferenceDataStore)` |   |

### setStorageDefault

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/preference#1.0.0)

```
public void setStorageDefault()
```

Sets the storage location used internally by this class to be the default provided by the hosting `https://developer.android.com/reference/android/content/Context.html`.

### setStorageDeviceProtected

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/preference#1.0.0)

```
public void setStorageDeviceProtected()
```

Explicitly set the storage location used internally by this class to be device-protected storage.

On devices with direct boot, data stored in this location is encrypted with a key tied to the physical device, and it can be accessed immediately after the device has booted successfully, both *before and after* the user has authenticated with their credentials (such as a lock pattern or PIN).

Because device-protected data is available without user authentication, you should carefully limit the data you store using this Context. For example, storing sensitive authentication tokens or passwords in the device-protected area is strongly discouraged.

Prior to API 24 this method has no effect, since device-protected storage is not available.

| See also |
|---|---|
| `https://developer.android.com/reference/android/content/Context.html#createDeviceProtectedStorageContext()` |   |

### showDialog

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/preference#1.0.0)

```
public void showDialog(@NonNull Preference preference)
```

Called when a preference requests that a dialog be shown to complete a user interaction.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/preference/Preference preference` | The preference requesting the dialog |