# PreferenceManager

# 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)

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/preference/PreferenceManager "View this page in Java")

<br />

```
class PreferenceManager
```

<br />

*** ** * ** ***

Used to help create[Preference](https://developer.android.com/reference/kotlin/androidx/preference/Preference)hierarchies from activities or XML.

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

|                                                        See also                                                         |
|-------------------------------------------------------------------------------------------------------------------------|---|
| [PreferenceFragmentCompat](https://developer.android.com/reference/kotlin/androidx/preference/PreferenceFragmentCompat) |   |

## Summary

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

|                                        ### Constants                                         |
|----------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `const `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`!` | [KEY_HAS_SET_DEFAULT_VALUES](https://developer.android.com/reference/kotlin/androidx/preference/PreferenceManager#KEY_HAS_SET_DEFAULT_VALUES())` = "_has_set_default_values"` |

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

```
const val KEY_HAS_SET_DEFAULT_VALUES = "_has_set_default_values": String!
```  

## Public functions

### createPreferenceScreen

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

```
fun createPreferenceScreen(context: Context): PreferenceScreen
```  

### findPreference

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

```
fun <T : Preference?> findPreference(key: CharSequence): T?
```

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

|                                              Parameters                                               |
|-------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------|
| `key: `[CharSequence](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-char-sequence/index.html) | The key of the[Preference](https://developer.android.com/reference/kotlin/androidx/preference/Preference)to retrieve |

| Returns |
|---------|----------------------------------------------------------------------------------------------------------------------|
| `T?`    | The[Preference](https://developer.android.com/reference/kotlin/androidx/preference/Preference)with the key, or`null` |

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

### getContext

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

```
fun getContext(): Context
```

Returns the context.  

|                                     Returns                                     |
|---------------------------------------------------------------------------------|------------------------------------------------------------------------------------|
| [Context](https://developer.android.com/reference/android/content/Context.html) | The[Context](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)  

```
java-static fun getDefaultSharedPreferences(context: Context): SharedPreferences!
```

Gets a[SharedPreferences](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                                         |
|--------------------------------------------------------------------------------------------|--------------------------------------------------------|
| `context: `[Context](https://developer.android.com/reference/android/content/Context.html) | The context of the preferences whose values are wanted |

|                                                Returns                                                 |
|--------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [SharedPreferences](https://developer.android.com/reference/android/content/SharedPreferences.html)`!` | A[SharedPreferences](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)  

```
fun getOnDisplayPreferenceDialogListener(): PreferenceManager.OnDisplayPreferenceDialogListener?
```  

### getOnNavigateToScreenListener

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

```
fun getOnNavigateToScreenListener(): PreferenceManager.OnNavigateToScreenListener?
```

Returns the[PreferenceManager.OnNavigateToScreenListener](https://developer.android.com/reference/kotlin/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)  

```
fun getOnPreferenceTreeClickListener(): PreferenceManager.OnPreferenceTreeClickListener?
```  

### getPreferenceComparisonCallback

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

```
fun getPreferenceComparisonCallback(): PreferenceManager.PreferenceComparisonCallback?
```  

### getPreferenceDataStore

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

```
fun getPreferenceDataStore(): PreferenceDataStore?
```

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

|                                                     Returns                                                      |
|------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [PreferenceDataStore](https://developer.android.com/reference/kotlin/androidx/preference/PreferenceDataStore)`?` | The[PreferenceDataStore](https://developer.android.com/reference/kotlin/androidx/preference/PreferenceDataStore)associated with this manager or`null`if none |

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

### getPreferenceScreen

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

```
fun getPreferenceScreen(): PreferenceScreen!
```

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

|                                                  Returns                                                   |
|------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------|
| [PreferenceScreen](https://developer.android.com/reference/kotlin/androidx/preference/PreferenceScreen)`!` | The[PreferenceScreen](https://developer.android.com/reference/kotlin/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)  

```
fun getSharedPreferences(): SharedPreferences?
```

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

|                                                Returns                                                 |
|--------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [SharedPreferences](https://developer.android.com/reference/android/content/SharedPreferences.html)`?` | A[SharedPreferences](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[PreferenceDataStore](https://developer.android.com/reference/kotlin/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)  

```
fun getSharedPreferencesMode(): Int
```

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

|                                   Returns                                   |
|-----------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | The mode that can be passed to[getSharedPreferences](https://developer.android.com/reference/android/content/Context.html#getSharedPreferences(java.lang.String, int)) |

|                                                                 See also                                                                 |
|------------------------------------------------------------------------------------------------------------------------------------------|---|
| [getSharedPreferences](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)  

```
fun getSharedPreferencesName(): String!
```

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

|                                       Returns                                        |
|--------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`!` | The name that can be passed to[getSharedPreferences](https://developer.android.com/reference/android/content/Context.html#getSharedPreferences(java.lang.String, int)) |

|                                                                 See also                                                                 |
|------------------------------------------------------------------------------------------------------------------------------------------|---|
| [getSharedPreferences](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)  

```
fun isStorageDefault(): Boolean
```

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

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

### isStorageDeviceProtected

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

```
fun isStorageDeviceProtected(): Boolean
```

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

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

### setDefaultValues

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

```
java-static fun setDefaultValues(context: Context, resId: Int, readAgain: Boolean): Unit
```

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

|                                            Parameters                                            |
|--------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `context: `[Context](https://developer.android.com/reference/android/content/Context.html)       | The context of the shared preferences                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| `resId: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)             | The resource ID of the preference XML file                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| `readAgain: `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | 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[KEY_HAS_SET_DEFAULT_VALUES](https://developer.android.com/reference/kotlin/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[getDefaultSharedPreferences](https://developer.android.com/reference/kotlin/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)  

```
java-static fun setDefaultValues(
    context: Context,
    sharedPreferencesName: String!,
    sharedPreferencesMode: Int,
    resId: Int,
    readAgain: Boolean
): Unit
```

Similar to[setDefaultValues](https://developer.android.com/reference/kotlin/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                                                   |
|---------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `context: `[Context](https://developer.android.com/reference/android/content/Context.html)                    | The context of the shared preferences                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| `sharedPreferencesName: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`!` | A custom name for the shared preferences file                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| `sharedPreferencesMode: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)          | The file creation mode for the shared preferences file, such as[MODE_PRIVATE](https://developer.android.com/reference/android/content/Context.html#MODE_PRIVATE())or[MODE_PRIVATE](https://developer.android.com/reference/android/content/Context.html#MODE_PRIVATE()).                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| `resId: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                          | The resource ID of the preference XML file                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| `readAgain: `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)              | 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[KEY_HAS_SET_DEFAULT_VALUES](https://developer.android.com/reference/kotlin/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[getDefaultSharedPreferences](https://developer.android.com/reference/kotlin/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                                                                            |
|----------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| [setDefaultValues](https://developer.android.com/reference/kotlin/androidx/preference/PreferenceManager#setDefaultValues(android.content.Context,int,boolean)) |   |
| [setSharedPreferencesName](https://developer.android.com/reference/kotlin/androidx/preference/PreferenceManager#setSharedPreferencesName(java.lang.String))    |   |
| [setSharedPreferencesMode](https://developer.android.com/reference/kotlin/androidx/preference/PreferenceManager#setSharedPreferencesMode(int))                 |   |

### setOnDisplayPreferenceDialogListener

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

```
fun setOnDisplayPreferenceDialogListener(
    onDisplayPreferenceDialogListener: PreferenceManager.OnDisplayPreferenceDialogListener?
): Unit
```  

### setOnNavigateToScreenListener

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

```
fun setOnNavigateToScreenListener(
    listener: PreferenceManager.OnNavigateToScreenListener?
): Unit
```

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

|                                                                                   Parameters                                                                                   |
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------|
| `listener: `[PreferenceManager.OnNavigateToScreenListener](https://developer.android.com/reference/kotlin/androidx/preference/PreferenceManager.OnNavigateToScreenListener)`?` | The callback to be invoked |

### setOnPreferenceTreeClickListener

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

```
fun setOnPreferenceTreeClickListener(
    listener: PreferenceManager.OnPreferenceTreeClickListener?
): Unit
```

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

|                                                                                      Parameters                                                                                      |
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------|
| `listener: `[PreferenceManager.OnPreferenceTreeClickListener](https://developer.android.com/reference/kotlin/androidx/preference/PreferenceManager.OnPreferenceTreeClickListener)`?` | The callback to be invoked |

### setPreferenceComparisonCallback

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

```
fun setPreferenceComparisonCallback(
    preferenceComparisonCallback: PreferenceManager.PreferenceComparisonCallback?
): Unit
```  

### setPreferenceDataStore

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

```
fun setPreferenceDataStore(dataStore: PreferenceDataStore?): Unit
```

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

|                                                          Parameters                                                           |
|-------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------|
| `dataStore: `[PreferenceDataStore](https://developer.android.com/reference/kotlin/androidx/preference/PreferenceDataStore)`?` | The[PreferenceDataStore](https://developer.android.com/reference/kotlin/androidx/preference/PreferenceDataStore)to be used by this manager |

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

### setPreferences

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

```
fun setPreferences(preferenceScreen: PreferenceScreen!): Boolean
```

Sets the root of the preference hierarchy.  

|                                                           Parameters                                                           |
|--------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------|
| `preferenceScreen: `[PreferenceScreen](https://developer.android.com/reference/kotlin/androidx/preference/PreferenceScreen)`!` | The root[PreferenceScreen](https://developer.android.com/reference/kotlin/androidx/preference/PreferenceScreen)of the preference hierarchy |

|                                       Returns                                       |
|-------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | Whether the[PreferenceScreen](https://developer.android.com/reference/kotlin/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)  

```
fun setSharedPreferencesMode(sharedPreferencesMode: Int): Unit
```

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

|                                              Parameters                                              |
|------------------------------------------------------------------------------------------------------|----------------------------------------|
| `sharedPreferencesMode: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | The mode of the SharedPreferences file |

|                                                                 See also                                                                 |
|------------------------------------------------------------------------------------------------------------------------------------------|---|
| [getSharedPreferences](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)  

```
fun setSharedPreferencesName(sharedPreferencesName: String!): Unit
```

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

If custom[PreferenceDataStore](https://developer.android.com/reference/kotlin/androidx/preference/PreferenceDataStore)is set, this won't override its usage.  

|                                                  Parameters                                                   |
|---------------------------------------------------------------------------------------------------------------|----------------------------------------|
| `sharedPreferencesName: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`!` | The name of the SharedPreferences file |

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

### setStorageDefault

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

```
fun setStorageDefault(): Unit
```

Sets the storage location used internally by this class to be the default provided by the hosting[Context](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)  

```
fun setStorageDeviceProtected(): Unit
```

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                                                                      |
|---------------------------------------------------------------------------------------------------------------------------------------------------|---|
| [createDeviceProtectedStorageContext](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)  

```
fun showDialog(preference: Preference): Unit
```

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

|                                                Parameters                                                 |
|-----------------------------------------------------------------------------------------------------------|--------------------------------------|
| `preference: `[Preference](https://developer.android.com/reference/kotlin/androidx/preference/Preference) | The preference requesting the dialog |