Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)   
Deprecated in [API level
29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Nested Classes](https://developer.android.com/reference/android/preference/Preference#nestedclasses) \| [XML Attrs](https://developer.android.com/reference/android/preference/Preference#lattrs) \| [Constants](https://developer.android.com/reference/android/preference/Preference#constants) \| [Ctors](https://developer.android.com/reference/android/preference/Preference#pubctors) \| [Methods](https://developer.android.com/reference/android/preference/Preference#pubmethods) \| [Protected Methods](https://developer.android.com/reference/android/preference/Preference#promethods) \| [Inherited Methods](https://developer.android.com/reference/android/preference/Preference#inhmethods)

# Preference

*** ** * ** ***


`
public


class
Preference
`


`

extends https://developer.android.com/reference/java/lang/Object


`

`


implements

https://developer.android.com/reference/java/lang/Comparable<https://developer.android.com/reference/android/preference/Preference>


`

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.preference.Preference |

|---|
| Known direct subclasses [DialogPreference](https://developer.android.com/reference/android/preference/DialogPreference), [PreferenceGroup](https://developer.android.com/reference/android/preference/PreferenceGroup), [RingtonePreference](https://developer.android.com/reference/android/preference/RingtonePreference), [TwoStatePreference](https://developer.android.com/reference/android/preference/TwoStatePreference) |---|---| | [DialogPreference](https://developer.android.com/reference/android/preference/DialogPreference) | *This class was deprecated in API level 29. Use the [AndroidX](https://developer.android.com/jetpack/androidx) [Preference Library](https://developer.android.com/reference/androidx/preference/package-summary) for consistent behavior across all devices. For more information on using the AndroidX Preference Library see [Settings](https://developer.android.com/guide/topics/ui/settings).* | | [PreferenceGroup](https://developer.android.com/reference/android/preference/PreferenceGroup) | *This class was deprecated in API level 29. Use the [AndroidX](https://developer.android.com/jetpack/androidx) [Preference Library](https://developer.android.com/reference/androidx/preference/package-summary) for consistent behavior across all devices. For more information on using the AndroidX Preference Library see [Settings](https://developer.android.com/guide/topics/ui/settings).* | | [RingtonePreference](https://developer.android.com/reference/android/preference/RingtonePreference) | *This class was deprecated in API level 29. Use the [AndroidX](https://developer.android.com/jetpack/androidx) [Preference Library](https://developer.android.com/reference/androidx/preference/package-summary) for consistent behavior across all devices. For more information on using the AndroidX Preference Library see [Settings](https://developer.android.com/guide/topics/ui/settings).* | | [TwoStatePreference](https://developer.android.com/reference/android/preference/TwoStatePreference) | *This class was deprecated in API level 29. Use the [AndroidX](https://developer.android.com/jetpack/androidx) [Preference Library](https://developer.android.com/reference/androidx/preference/package-summary) for consistent behavior across all devices. For more information on using the AndroidX Preference Library see [Settings](https://developer.android.com/guide/topics/ui/settings).* | |

|---|
| Known indirect subclasses [CheckBoxPreference](https://developer.android.com/reference/android/preference/CheckBoxPreference), [EditTextPreference](https://developer.android.com/reference/android/preference/EditTextPreference), [ListPreference](https://developer.android.com/reference/android/preference/ListPreference), [MultiSelectListPreference](https://developer.android.com/reference/android/preference/MultiSelectListPreference), [PreferenceCategory](https://developer.android.com/reference/android/preference/PreferenceCategory), [PreferenceScreen](https://developer.android.com/reference/android/preference/PreferenceScreen), [SwitchPreference](https://developer.android.com/reference/android/preference/SwitchPreference) |---|---| | [CheckBoxPreference](https://developer.android.com/reference/android/preference/CheckBoxPreference) | *This class was deprecated in API level 29. Use the [AndroidX](https://developer.android.com/jetpack/androidx) [Preference Library](https://developer.android.com/reference/androidx/preference/package-summary) for consistent behavior across all devices. For more information on using the AndroidX Preference Library see [Settings](https://developer.android.com/guide/topics/ui/settings).* | | [EditTextPreference](https://developer.android.com/reference/android/preference/EditTextPreference) | *This class was deprecated in API level 29. Use the [AndroidX](https://developer.android.com/jetpack/androidx) [Preference Library](https://developer.android.com/reference/androidx/preference/package-summary) for consistent behavior across all devices. For more information on using the AndroidX Preference Library see [Settings](https://developer.android.com/guide/topics/ui/settings).* | | [ListPreference](https://developer.android.com/reference/android/preference/ListPreference) | *This class was deprecated in API level 29. Use the [AndroidX](https://developer.android.com/jetpack/androidx) [Preference Library](https://developer.android.com/reference/androidx/preference/package-summary) for consistent behavior across all devices. For more information on using the AndroidX Preference Library see [Settings](https://developer.android.com/guide/topics/ui/settings).* | | [MultiSelectListPreference](https://developer.android.com/reference/android/preference/MultiSelectListPreference) | *This class was deprecated in API level 29. Use the [AndroidX](https://developer.android.com/jetpack/androidx) [Preference Library](https://developer.android.com/reference/androidx/preference/package-summary) for consistent behavior across all devices. For more information on using the AndroidX Preference Library see [Settings](https://developer.android.com/guide/topics/ui/settings).* | | [PreferenceCategory](https://developer.android.com/reference/android/preference/PreferenceCategory) | *This class was deprecated in API level 29. Use the [AndroidX](https://developer.android.com/jetpack/androidx) [Preference Library](https://developer.android.com/reference/androidx/preference/package-summary) for consistent behavior across all devices. For more information on using the AndroidX Preference Library see [Settings](https://developer.android.com/guide/topics/ui/settings).* | | [PreferenceScreen](https://developer.android.com/reference/android/preference/PreferenceScreen) | *This class was deprecated in API level 29. Use the [AndroidX](https://developer.android.com/jetpack/androidx) [Preference Library](https://developer.android.com/reference/androidx/preference/package-summary) for consistent behavior across all devices. For more information on using the AndroidX Preference Library see [Settings](https://developer.android.com/guide/topics/ui/settings).* | | [SwitchPreference](https://developer.android.com/reference/android/preference/SwitchPreference) | *This class was deprecated in API level 29. Use the [AndroidX](https://developer.android.com/jetpack/androidx) [Preference Library](https://developer.android.com/reference/androidx/preference/package-summary) for consistent behavior across all devices. For more information on using the AndroidX Preference Library see [Settings](https://developer.android.com/guide/topics/ui/settings).* | |

<br />

*** ** * ** ***


**This class was deprecated
in API level 29.**   

Use the [AndroidX](https://developer.android.com/jetpack/androidx)
[Preference Library](https://developer.android.com/reference/androidx/preference/package-summary) for consistent behavior across all devices. For more information on
using the AndroidX Preference Library see
[Settings](https://developer.android.com/guide/topics/ui/settings).

Represents the basic Preference UI building
block displayed by a `https://developer.android.com/reference/android/preference/PreferenceActivity` in the form of a
`https://developer.android.com/reference/android/widget/ListView`. This class provides the `https://developer.android.com/reference/android/view/View` to be displayed in
the activity and associates with a `https://developer.android.com/reference/android/content/SharedPreferences` to
store/retrieve the preference data.


When specifying a preference hierarchy in XML, each element can point to a
subclass of `https://developer.android.com/reference/android/preference/Preference`, similar to the view hierarchy and layouts.


This class contains a `key` that will be used as the key into the
`https://developer.android.com/reference/android/content/SharedPreferences`. It is up to the subclass to decide how to store
the value.

### Developer Guides

For information about building a settings UI with Preferences,
read the [Settings](https://developer.android.com/guide/topics/ui/settings)
guide.

<br />

## Summary

| ### Nested classes ||
|---|---|
| ` class` | `https://developer.android.com/reference/android/preference/Preference.BaseSavedState` *This class was deprecated in API level 29. Use the [AndroidX](https://developer.android.com/jetpack/androidx) [Preference Library](https://developer.android.com/reference/androidx/preference/package-summary) for consistent behavior across all devices. For more information on using the AndroidX Preference Library see [Settings](https://developer.android.com/guide/topics/ui/settings).* |
| ` interface` | `https://developer.android.com/reference/android/preference/Preference.OnPreferenceChangeListener` *This interface was deprecated in API level 29. Use the [AndroidX](https://developer.android.com/jetpack/androidx) [Preference Library](https://developer.android.com/reference/androidx/preference/package-summary) for consistent behavior across all devices. For more information on using the AndroidX Preference Library see [Settings](https://developer.android.com/guide/topics/ui/settings).* |
| ` interface` | `https://developer.android.com/reference/android/preference/Preference.OnPreferenceClickListener` *This interface was deprecated in API level 29. Use the [AndroidX](https://developer.android.com/jetpack/androidx) [Preference Library](https://developer.android.com/reference/androidx/preference/package-summary) for consistent behavior across all devices. For more information on using the AndroidX Preference Library see [Settings](https://developer.android.com/guide/topics/ui/settings).* |

| ### XML attributes ||
|---|---|
| [`android:defaultValue`](https://developer.android.com/reference/android/preference/Preference#attr_android:defaultValue) | The default value for the preference, which will be set either if persistence is off or persistence is on and the preference is not found in the persistent storage. |
| [`android:dependency`](https://developer.android.com/reference/android/preference/Preference#attr_android:dependency) | The key of another Preference that this Preference will depend on. |
| [`android:enabled`](https://developer.android.com/reference/android/preference/Preference#attr_android:enabled) | Whether the Preference is enabled. |
| [`android:fragment`](https://developer.android.com/reference/android/preference/Preference#attr_android:fragment) | When used inside of a modern PreferenceActivity, this declares a new PreferenceFragment to be shown when the user selects this item. |
| [`android:icon`](https://developer.android.com/reference/android/preference/Preference#attr_android:icon) | The optional icon for the preference. |
| [`android:iconSpaceReserved`](https://developer.android.com/reference/android/preference/Preference#attr_android:iconSpaceReserved) | Whether the space for the preference icon view will be reserved. |
| [`android:key`](https://developer.android.com/reference/android/preference/Preference#attr_android:key) | The key to store the Preference value. |
| [`android:layout`](https://developer.android.com/reference/android/preference/Preference#attr_android:layout) | The layout for the Preference in a PreferenceActivity screen. |
| [`android:order`](https://developer.android.com/reference/android/preference/Preference#attr_android:order) | The order for the Preference (lower values are to be ordered first). |
| [`android:persistent`](https://developer.android.com/reference/android/preference/Preference#attr_android:persistent) | Whether the Preference stores its value to the storage. |
| [`android:recycleEnabled`](https://developer.android.com/reference/android/preference/Preference#attr_android:recycleEnabled) | Whether the preference has enabled to have its view recycled when used in the list view. |
| [`android:selectable`](https://developer.android.com/reference/android/preference/Preference#attr_android:selectable) | Whether the Preference is selectable. |
| [`android:shouldDisableView`](https://developer.android.com/reference/android/preference/Preference#attr_android:shouldDisableView) | Whether the view of this Preference should be disabled when this Preference is disabled. |
| [`android:singleLineTitle`](https://developer.android.com/reference/android/preference/Preference#attr_android:singleLineTitle) | Whether to use single line for the preference title text. |
| [`android:summary`](https://developer.android.com/reference/android/preference/Preference#attr_android:summary) | The summary for the Preference. |
| [`android:title`](https://developer.android.com/reference/android/preference/Preference#attr_android:title) | The title for the Preference. |
| [`android:widgetLayout`](https://developer.android.com/reference/android/preference/Preference#attr_android:widgetLayout) | The layout for the controllable widget portion of a Preference. |

| ### Constants ||
|---|---|
| `int` | `https://developer.android.com/reference/android/preference/Preference#DEFAULT_ORDER` Specify for `https://developer.android.com/reference/android/preference/Preference#setOrder(int)` if a specific order is not required. |

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/android/preference/Preference#Preference(android.content.Context)(https://developer.android.com/reference/android/content/Context context) ` Constructor to create a Preference. |
| ` https://developer.android.com/reference/android/preference/Preference#Preference(android.content.Context,%20android.util.AttributeSet)(https://developer.android.com/reference/android/content/Context context, https://developer.android.com/reference/android/util/AttributeSet attrs) ` Constructor that is called when inflating a Preference from XML. |
| ` https://developer.android.com/reference/android/preference/Preference#Preference(android.content.Context,%20android.util.AttributeSet,%20int)(https://developer.android.com/reference/android/content/Context context, https://developer.android.com/reference/android/util/AttributeSet attrs, int defStyleAttr) ` Perform inflation from XML and apply a class-specific base style. |
| ` https://developer.android.com/reference/android/preference/Preference#Preference(android.content.Context,%20android.util.AttributeSet,%20int,%20int)(https://developer.android.com/reference/android/content/Context context, https://developer.android.com/reference/android/util/AttributeSet attrs, int defStyleAttr, int defStyleRes) ` Perform inflation from XML and apply a class-specific base style. |

| ### Public methods ||
|---|---|
| ` int` | ` https://developer.android.com/reference/android/preference/Preference#compareTo(android.preference.Preference)(https://developer.android.com/reference/android/preference/Preference another) ` Compares Preference objects based on order (if set), otherwise alphabetically on the titles. |
| ` https://developer.android.com/reference/android/content/Context` | ` https://developer.android.com/reference/android/preference/Preference#getContext()() ` Returns the `https://developer.android.com/reference/android/content/Context` of this Preference. |
| ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/android/preference/Preference#getDependency()() ` Returns the key of the dependency on this Preference. |
| ` https://developer.android.com/reference/android/content/SharedPreferences.Editor` | ` https://developer.android.com/reference/android/preference/Preference#getEditor()() ` Returns an `https://developer.android.com/reference/android/content/SharedPreferences.Editor` where this Preference can save its value(s). |
| ` https://developer.android.com/reference/android/os/Bundle` | ` https://developer.android.com/reference/android/preference/Preference#getExtras()() ` Return the extras Bundle object associated with this preference, creating a new Bundle if there currently isn't one. |
| ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/android/preference/Preference#getFragment()() ` Return the fragment class name associated with this Preference. |
| ` https://developer.android.com/reference/android/graphics/drawable/Drawable` | ` https://developer.android.com/reference/android/preference/Preference#getIcon()() ` Returns the icon of this Preference. |
| ` https://developer.android.com/reference/android/content/Intent` | ` https://developer.android.com/reference/android/preference/Preference#getIntent()() ` Return the `https://developer.android.com/reference/android/content/Intent` associated with this Preference. |
| ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/android/preference/Preference#getKey()() ` Gets the key for this Preference, which is also the key used for storing values into `https://developer.android.com/reference/android/content/SharedPreferences` or `https://developer.android.com/reference/android/preference/PreferenceDataStore`. |
| ` int` | ` https://developer.android.com/reference/android/preference/Preference#getLayoutResource()() ` Gets the layout resource that will be shown as the `https://developer.android.com/reference/android/view/View` for this Preference. |
| ` https://developer.android.com/reference/android/preference/Preference.OnPreferenceChangeListener` | ` https://developer.android.com/reference/android/preference/Preference#getOnPreferenceChangeListener()() ` Returns the callback to be invoked when this Preference is changed by the user (but before the internal state has been updated). |
| ` https://developer.android.com/reference/android/preference/Preference.OnPreferenceClickListener` | ` https://developer.android.com/reference/android/preference/Preference#getOnPreferenceClickListener()() ` Returns the callback to be invoked when this Preference is clicked. |
| ` int` | ` https://developer.android.com/reference/android/preference/Preference#getOrder()() ` Gets the order of this Preference with respect to other Preference objects on the same level. |
| ` https://developer.android.com/reference/android/preference/PreferenceGroup` | ` https://developer.android.com/reference/android/preference/Preference#getParent()() ` Returns the `https://developer.android.com/reference/android/preference/PreferenceGroup` which is this Preference assigned to or `null` if this preference is not assigned to any group or is a root Preference. |
| ` https://developer.android.com/reference/java/util/Set<https://developer.android.com/reference/java/lang/String>` | ` https://developer.android.com/reference/android/preference/Preference#getPersistedStringSet(java.util.Set<java.lang.String>)(https://developer.android.com/reference/java/util/Set<https://developer.android.com/reference/java/lang/String> defaultReturnValue) ` Attempts to get a persisted set of Strings if this Preference is persistent. |
| ` https://developer.android.com/reference/android/preference/PreferenceDataStore` | ` https://developer.android.com/reference/android/preference/Preference#getPreferenceDataStore()() ` Returns `https://developer.android.com/reference/android/preference/PreferenceDataStore` used by this Preference. |
| ` https://developer.android.com/reference/android/preference/PreferenceManager` | ` https://developer.android.com/reference/android/preference/Preference#getPreferenceManager()() ` Gets the `https://developer.android.com/reference/android/preference/PreferenceManager` that manages this Preference object's tree. |
| ` https://developer.android.com/reference/android/content/SharedPreferences` | ` https://developer.android.com/reference/android/preference/Preference#getSharedPreferences()() ` Returns the `https://developer.android.com/reference/android/content/SharedPreferences` where this Preference can read its value(s). |
| ` boolean` | ` https://developer.android.com/reference/android/preference/Preference#getShouldDisableView()() ` Checks whether this Preference should disable its view when it's action is disabled. |
| ` https://developer.android.com/reference/java/lang/CharSequence` | ` https://developer.android.com/reference/android/preference/Preference#getSummary()() ` Returns the summary of this Preference. |
| ` https://developer.android.com/reference/java/lang/CharSequence` | ` https://developer.android.com/reference/android/preference/Preference#getTitle()() ` Returns the title of this Preference. |
| ` int` | ` https://developer.android.com/reference/android/preference/Preference#getTitleRes()() ` Returns the title resource ID of this Preference. |
| ` https://developer.android.com/reference/android/view/View` | ` https://developer.android.com/reference/android/preference/Preference#getView(android.view.View,%20android.view.ViewGroup)(https://developer.android.com/reference/android/view/View convertView, https://developer.android.com/reference/android/view/ViewGroup parent) ` Gets the View that will be shown in the `https://developer.android.com/reference/android/preference/PreferenceActivity`. |
| ` int` | ` https://developer.android.com/reference/android/preference/Preference#getWidgetLayoutResource()() ` Gets the layout resource for the controllable widget portion of this Preference. |
| ` boolean` | ` https://developer.android.com/reference/android/preference/Preference#hasKey()() ` Checks whether this Preference has a valid key. |
| ` boolean` | ` https://developer.android.com/reference/android/preference/Preference#isEnabled()() ` Checks whether this Preference should be enabled in the list. |
| ` boolean` | ` https://developer.android.com/reference/android/preference/Preference#isIconSpaceReserved()() ` Gets whether the space this preference icon view is reserved. |
| ` boolean` | ` https://developer.android.com/reference/android/preference/Preference#isPersistent()() ` Checks whether this Preference is persistent. |
| ` boolean` | ` https://developer.android.com/reference/android/preference/Preference#isRecycleEnabled()() ` Checks whether this Preference has enabled to have its view recycled when used in the list view. |
| ` boolean` | ` https://developer.android.com/reference/android/preference/Preference#isSelectable()() ` Checks whether this Preference should be selectable in the list. |
| ` boolean` | ` https://developer.android.com/reference/android/preference/Preference#isSingleLineTitle()() ` Gets whether the title of this preference is constrained to a single line. |
| ` void` | ` https://developer.android.com/reference/android/preference/Preference#notifyDependencyChange(boolean)(boolean disableDependents) ` Notifies any listening dependents of a change that affects the dependency. |
| ` void` | ` https://developer.android.com/reference/android/preference/Preference#onDependencyChanged(android.preference.Preference,%20boolean)(https://developer.android.com/reference/android/preference/Preference dependency, boolean disableDependent) ` Called when the dependency changes. |
| ` void` | ` https://developer.android.com/reference/android/preference/Preference#onParentChanged(android.preference.Preference,%20boolean)(https://developer.android.com/reference/android/preference/Preference parent, boolean disableChild) ` Called when the implicit parent dependency changes. |
| ` https://developer.android.com/reference/android/os/Bundle` | ` https://developer.android.com/reference/android/preference/Preference#peekExtras()() ` Return the extras Bundle object associated with this preference, returning `null` if there is not currently one. |
| ` boolean` | ` https://developer.android.com/reference/android/preference/Preference#persistStringSet(java.util.Set<java.lang.String>)(https://developer.android.com/reference/java/util/Set<https://developer.android.com/reference/java/lang/String> values) ` Attempts to persist a set of Strings if this Preference is persistent. |
| ` void` | ` https://developer.android.com/reference/android/preference/Preference#restoreHierarchyState(android.os.Bundle)(https://developer.android.com/reference/android/os/Bundle container) ` Restore this Preference hierarchy's previously saved state from the given container. |
| ` void` | ` https://developer.android.com/reference/android/preference/Preference#saveHierarchyState(android.os.Bundle)(https://developer.android.com/reference/android/os/Bundle container) ` Store this Preference hierarchy's frozen state into the given container. |
| ` void` | ` https://developer.android.com/reference/android/preference/Preference#setDefaultValue(java.lang.Object)(https://developer.android.com/reference/java/lang/Object defaultValue) ` Sets the default value for this Preference, which will be set either if persistence is off or persistence is on and the preference is not found in the persistent storage. |
| ` void` | ` https://developer.android.com/reference/android/preference/Preference#setDependency(java.lang.String)(https://developer.android.com/reference/java/lang/String dependencyKey) ` Sets the key of a Preference that this Preference will depend on. |
| ` void` | ` https://developer.android.com/reference/android/preference/Preference#setEnabled(boolean)(boolean enabled) ` Sets whether this Preference is enabled. |
| ` void` | ` https://developer.android.com/reference/android/preference/Preference#setFragment(java.lang.String)(https://developer.android.com/reference/java/lang/String fragment) ` Sets the class name of a fragment to be shown when this Preference is clicked. |
| ` void` | ` https://developer.android.com/reference/android/preference/Preference#setIcon(android.graphics.drawable.Drawable)(https://developer.android.com/reference/android/graphics/drawable/Drawable icon) ` Sets the icon for this Preference with a Drawable. |
| ` void` | ` https://developer.android.com/reference/android/preference/Preference#setIcon(int)(int iconResId) ` Sets the icon for this Preference with a resource ID. |
| ` void` | ` https://developer.android.com/reference/android/preference/Preference#setIconSpaceReserved(boolean)(boolean iconSpaceReserved) ` Sets whether to reserve the space of this Preference icon view when no icon is provided. |
| ` void` | ` https://developer.android.com/reference/android/preference/Preference#setIntent(android.content.Intent)(https://developer.android.com/reference/android/content/Intent intent) ` Sets an `https://developer.android.com/reference/android/content/Intent` to be used for `https://developer.android.com/reference/android/content/Context#startActivity(android.content.Intent)` when this Preference is clicked. |
| ` void` | ` https://developer.android.com/reference/android/preference/Preference#setKey(java.lang.String)(https://developer.android.com/reference/java/lang/String key) ` Sets the key for this Preference, which is used as a key to the `https://developer.android.com/reference/android/content/SharedPreferences` or `https://developer.android.com/reference/android/preference/PreferenceDataStore`. |
| ` void` | ` https://developer.android.com/reference/android/preference/Preference#setLayoutResource(int)(int layoutResId) ` Sets the layout resource that is inflated as the `https://developer.android.com/reference/android/view/View` to be shown for this Preference. |
| ` void` | ` https://developer.android.com/reference/android/preference/Preference#setOnPreferenceChangeListener(android.preference.Preference.OnPreferenceChangeListener)(https://developer.android.com/reference/android/preference/Preference.OnPreferenceChangeListener onPreferenceChangeListener) ` Sets the callback to be invoked when this Preference is changed by the user (but before the internal state has been updated). |
| ` void` | ` https://developer.android.com/reference/android/preference/Preference#setOnPreferenceClickListener(android.preference.Preference.OnPreferenceClickListener)(https://developer.android.com/reference/android/preference/Preference.OnPreferenceClickListener onPreferenceClickListener) ` Sets the callback to be invoked when this Preference is clicked. |
| ` void` | ` https://developer.android.com/reference/android/preference/Preference#setOrder(int)(int order) ` Sets the order of this Preference with respect to other Preference objects on the same level. |
| ` void` | ` https://developer.android.com/reference/android/preference/Preference#setPersistent(boolean)(boolean persistent) ` Sets whether this Preference is persistent. |
| ` void` | ` https://developer.android.com/reference/android/preference/Preference#setPreferenceDataStore(android.preference.PreferenceDataStore)(https://developer.android.com/reference/android/preference/PreferenceDataStore dataStore) ` Sets a `https://developer.android.com/reference/android/preference/PreferenceDataStore` to be used by this Preference instead of using `https://developer.android.com/reference/android/content/SharedPreferences`. |
| ` void` | ` https://developer.android.com/reference/android/preference/Preference#setRecycleEnabled(boolean)(boolean enabled) ` Sets whether this Preference has enabled to have its view recycled when used in the list view. |
| ` void` | ` https://developer.android.com/reference/android/preference/Preference#setSelectable(boolean)(boolean selectable) ` Sets whether this Preference is selectable. |
| ` void` | ` https://developer.android.com/reference/android/preference/Preference#setShouldDisableView(boolean)(boolean shouldDisableView) ` Sets whether this Preference should disable its view when it gets disabled. |
| ` void` | ` https://developer.android.com/reference/android/preference/Preference#setSingleLineTitle(boolean)(boolean singleLineTitle) ` Sets whether to constrain the title of this Preference to a single line instead of letting it wrap onto multiple lines. |
| ` void` | ` https://developer.android.com/reference/android/preference/Preference#setSummary(java.lang.CharSequence)(https://developer.android.com/reference/java/lang/CharSequence summary) ` Sets the summary for this Preference with a CharSequence. |
| ` void` | ` https://developer.android.com/reference/android/preference/Preference#setSummary(int)(int summaryResId) ` Sets the summary for this Preference with a resource ID. |
| ` void` | ` https://developer.android.com/reference/android/preference/Preference#setTitle(java.lang.CharSequence)(https://developer.android.com/reference/java/lang/CharSequence title) ` Sets the title for this Preference with a CharSequence. |
| ` void` | ` https://developer.android.com/reference/android/preference/Preference#setTitle(int)(int titleResId) ` Sets the title for this Preference with a resource ID. |
| ` void` | ` https://developer.android.com/reference/android/preference/Preference#setWidgetLayoutResource(int)(int widgetLayoutResId) ` Sets the layout for the controllable widget portion of this Preference. |
| ` boolean` | ` https://developer.android.com/reference/android/preference/Preference#shouldCommit()() ` Returns whether the `https://developer.android.com/reference/android/preference/Preference` should commit its saved value(s) in `https://developer.android.com/reference/android/preference/Preference#getEditor()`. |
| ` boolean` | ` https://developer.android.com/reference/android/preference/Preference#shouldDisableDependents()() ` Checks whether this preference's dependents should currently be disabled. |
| ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/android/preference/Preference#toString()() ` Returns a string representation of the object. |

| ### Protected methods ||
|---|---|
| ` boolean` | ` https://developer.android.com/reference/android/preference/Preference#callChangeListener(java.lang.Object)(https://developer.android.com/reference/java/lang/Object newValue) ` Call this method after the user changes the preference, but before the internal state is set. |
| ` https://developer.android.com/reference/android/preference/Preference` | ` https://developer.android.com/reference/android/preference/Preference#findPreferenceInHierarchy(java.lang.String)(https://developer.android.com/reference/java/lang/String key) ` Finds a Preference in this hierarchy (the whole thing, even above/below your `https://developer.android.com/reference/android/preference/PreferenceScreen` screen break) with the given key. |
| ` boolean` | ` https://developer.android.com/reference/android/preference/Preference#getPersistedBoolean(boolean)(boolean defaultReturnValue) ` Attempts to get a persisted boolean if this Preference is persistent. |
| ` float` | ` https://developer.android.com/reference/android/preference/Preference#getPersistedFloat(float)(float defaultReturnValue) ` Attempts to get a persisted float if this Preference is persistent. |
| ` int` | ` https://developer.android.com/reference/android/preference/Preference#getPersistedInt(int)(int defaultReturnValue) ` Attempts to get a persisted int if this Preference is persistent. |
| ` long` | ` https://developer.android.com/reference/android/preference/Preference#getPersistedLong(long)(long defaultReturnValue) ` Attempts to get a persisted long if this Preference is persistent. |
| ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/android/preference/Preference#getPersistedString(java.lang.String)(https://developer.android.com/reference/java/lang/String defaultReturnValue) ` Attempts to get a persisted String if this Preference is persistent. |
| ` void` | ` https://developer.android.com/reference/android/preference/Preference#notifyChanged()() ` Should be called when the data of this `https://developer.android.com/reference/android/preference/Preference` has changed. |
| ` void` | ` https://developer.android.com/reference/android/preference/Preference#notifyHierarchyChanged()() ` Should be called when a Preference has been added/removed from this group, or the ordering should be re-evaluated. |
| ` void` | ` https://developer.android.com/reference/android/preference/Preference#onAttachedToActivity()() ` Called when the Preference hierarchy has been attached to the `https://developer.android.com/reference/android/preference/PreferenceActivity`. |
| ` void` | ` https://developer.android.com/reference/android/preference/Preference#onAttachedToHierarchy(android.preference.PreferenceManager)(https://developer.android.com/reference/android/preference/PreferenceManager preferenceManager) ` Called when this Preference has been attached to a Preference hierarchy. |
| ` void` | ` https://developer.android.com/reference/android/preference/Preference#onBindView(android.view.View)(https://developer.android.com/reference/android/view/View view) ` Binds the created View to the data for this Preference. |
| ` void` | ` https://developer.android.com/reference/android/preference/Preference#onClick()() ` Processes a click on the preference. |
| ` https://developer.android.com/reference/android/view/View` | ` https://developer.android.com/reference/android/preference/Preference#onCreateView(android.view.ViewGroup)(https://developer.android.com/reference/android/view/ViewGroup parent) ` Creates the View to be shown for this Preference in the `https://developer.android.com/reference/android/preference/PreferenceActivity`. |
| ` https://developer.android.com/reference/java/lang/Object` | ` https://developer.android.com/reference/android/preference/Preference#onGetDefaultValue(android.content.res.TypedArray,%20int)(https://developer.android.com/reference/android/content/res/TypedArray a, int index) ` Called when a Preference is being inflated and the default value attribute needs to be read. |
| ` void` | ` https://developer.android.com/reference/android/preference/Preference#onPrepareForRemoval()() ` Called when this Preference is being removed from the hierarchy. |
| ` void` | ` https://developer.android.com/reference/android/preference/Preference#onRestoreInstanceState(android.os.Parcelable)(https://developer.android.com/reference/android/os/Parcelable state) ` Hook allowing a Preference to re-apply a representation of its internal state that had previously been generated by `https://developer.android.com/reference/android/preference/Preference#onSaveInstanceState()`. |
| ` https://developer.android.com/reference/android/os/Parcelable` | ` https://developer.android.com/reference/android/preference/Preference#onSaveInstanceState()() ` Hook allowing a Preference to generate a representation of its internal state that can later be used to create a new instance with that same state. |
| ` void` | ` https://developer.android.com/reference/android/preference/Preference#onSetInitialValue(boolean,%20java.lang.Object)(boolean restorePersistedValue, https://developer.android.com/reference/java/lang/Object defaultValue) ` Implement this to set the initial value of the Preference. |
| ` boolean` | ` https://developer.android.com/reference/android/preference/Preference#persistBoolean(boolean)(boolean value) ` Attempts to persist a boolean if this Preference is persistent. |
| ` boolean` | ` https://developer.android.com/reference/android/preference/Preference#persistFloat(float)(float value) ` Attempts to persist a long if this Preference is persistent. |
| ` boolean` | ` https://developer.android.com/reference/android/preference/Preference#persistInt(int)(int value) ` Attempts to persist an int if this Preference is persistent. |
| ` boolean` | ` https://developer.android.com/reference/android/preference/Preference#persistLong(long)(long value) ` Attempts to persist a long if this Preference is persistent. |
| ` boolean` | ` https://developer.android.com/reference/android/preference/Preference#persistString(java.lang.String)(https://developer.android.com/reference/java/lang/String value) ` Attempts to persist a String if this Preference is persistent. |
| ` boolean` | ` https://developer.android.com/reference/android/preference/Preference#shouldPersist()() ` Checks whether, at the given time this method is called, this Preference should store/restore its value(s) into the `https://developer.android.com/reference/android/content/SharedPreferences` or into `https://developer.android.com/reference/android/preference/PreferenceDataStore` if assigned. |

| ### Inherited methods |
|---|---|
| From class ` https://developer.android.com/reference/java/lang/Object ` |---|---| | ` https://developer.android.com/reference/java/lang/Object` | ` https://developer.android.com/reference/java/lang/Object#clone()() ` Creates and returns a copy of this object. | | ` boolean` | ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) ` Indicates whether some other object is "equal to" this one. | | ` void` | ` https://developer.android.com/reference/java/lang/Object#finalize()() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. | | ` final https://developer.android.com/reference/java/lang/Class<?>` | ` https://developer.android.com/reference/java/lang/Object#getClass()() ` Returns the runtime class of this `Object`. | | ` int` | ` https://developer.android.com/reference/java/lang/Object#hashCode()() ` Returns a hash code value for the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notify()() ` Wakes up a single thread that is waiting on this object's monitor. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notifyAll()() ` Wakes up all threads that are waiting on this object's monitor. | | ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/java/lang/Object#toString()() ` Returns a string representation of the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait()() ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*. | ||
| From interface ` https://developer.android.com/reference/java/lang/Comparable ` |---|---| | ` abstract int` | ` https://developer.android.com/reference/java/lang/Comparable#compareTo(T)(https://developer.android.com/reference/android/preference/Preference o) ` Compares this object with the specified object for order. | ||

## XML attributes

### android:defaultValue

The default value for the preference, which will be set either if persistence
is off or persistence is on and the preference is not found in the persistent
storage.

May be a reference to another resource, in the form
"`@[+][*package*:]*type*/*name*`" or a theme
attribute in the form
"`?[*package*:]*type*/*name*`".

May be a string value, using '\\\\;' to escape characters such as
'\\\\n' or '\\\\uxxxx' for a unicode character;

May be an integer value, such as "`100`".

May be a boolean value, such as "`true`" or
"`false`".

May be a floating point value, such as "`1.2`".

<br />

### android:dependency

The key of another Preference that this Preference will depend on. If the other
Preference is not set or is off, this Preference will be disabled.

May be a string value, using '\\\\;' to escape characters such as
'\\\\n' or '\\\\uxxxx' for a unicode character;

<br />

### android:enabled

Whether the Preference is enabled.

May be a boolean value, such as "`true`" or
"`false`".

<br />

### android:fragment

When used inside of a modern PreferenceActivity, this declares
a new PreferenceFragment to be shown when the user selects this item.

May be a string value, using '\\\\;' to escape characters such as
'\\\\n' or '\\\\uxxxx' for a unicode character;

<br />

### android:icon

The optional icon for the preference.

May be a reference to another resource, in the form
"`@[+][*package*:]*type*/*name*`" or a theme
attribute in the form
"`?[*package*:]*type*/*name*`".

<br />

### android:iconSpaceReserved

Whether the space for the preference icon view will be reserved. By default, preference
icon view visibility will be set to GONE when there is no icon provided, so the default
value of this attribute is false.

May be a boolean value, such as "`true`" or
"`false`".

<br />

### android:key

The key to store the Preference value.

May be a string value, using '\\\\;' to escape characters such as
'\\\\n' or '\\\\uxxxx' for a unicode character;

<br />

### android:layout

The layout for the Preference in a PreferenceActivity screen. This should
rarely need to be changed, look at widgetLayout instead.

May be a reference to another resource, in the form
"`@[+][*package*:]*type*/*name*`" or a theme
attribute in the form
"`?[*package*:]*type*/*name*`".

<br />

### android:order

The order for the Preference (lower values are to be ordered first). If this is not
specified, the default ordering will be alphabetic.

May be an integer value, such as "`100`".

<br />

### android:persistent

Whether the Preference stores its value to the storage.

May be a boolean value, such as "`true`" or
"`false`".

<br />

### android:recycleEnabled

Whether the preference has enabled to have its view recycled when used in the list
view. This is true by default.

May be a boolean value, such as "`true`" or
"`false`".

<br />

### android:selectable

Whether the Preference is selectable.

May be a boolean value, such as "`true`" or
"`false`".

<br />

### android:shouldDisableView

Whether the view of this Preference should be disabled when
this Preference is disabled.

May be a boolean value, such as "`true`" or
"`false`".

<br />

### android:singleLineTitle

Whether to use single line for the preference title text. By default, preference title
will be constrained to one line, so the default value of this attribute is true.

May be a boolean value, such as "`true`" or
"`false`".

<br />

### android:summary

The summary for the Preference. In API 25 and earlier, this value is read as a
plain string with styling information stripped.

May be a string value, using '\\\\;' to escape characters such as
'\\\\n' or '\\\\uxxxx' for a unicode character;

<br />

### android:title

The title for the Preference. In API 25 and earlier, this value is read as a
plain string with styling information stripped.

May be a string value, using '\\\\;' to escape characters such as
'\\\\n' or '\\\\uxxxx' for a unicode character;

<br />

### android:widgetLayout

The layout for the controllable widget portion of a Preference. This is inflated
into the layout for a Preference and should be used more frequently than
the layout attribute. For example, a checkbox preference would specify
a custom layout (consisting of just the CheckBox) here.

May be a reference to another resource, in the form
"`@[+][*package*:]*type*/*name*`" or a theme
attribute in the form
"`?[*package*:]*type*/*name*`".

<br />

## Constants

### DEFAULT_ORDER

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int DEFAULT_ORDER
```

Specify for `https://developer.android.com/reference/android/preference/Preference#setOrder(int)` if a specific order is not required.

<br />

Constant Value:

2147483647
(0x7fffffff)


## Public constructors

### Preference

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public Preference (Context context)
```

Constructor to create a Preference.

<br />

| Parameters ||
|---|---|
| `context` | `Context`: The Context in which to store Preference values. <br /> |

### Preference

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public Preference (Context context, 
                AttributeSet attrs)
```

Constructor that is called when inflating a Preference from XML. This is
called when a Preference is being constructed from an XML file, supplying
attributes that were specified in the XML file. This version uses a
default style of 0, so the only attribute values applied are those in the
Context's Theme and the given AttributeSet.

<br />

| Parameters ||
|---|---|
| `context` | `Context`: The Context this is associated with, through which it can access the current theme, resources, `https://developer.android.com/reference/android/content/SharedPreferences`, etc. <br /> |
| `attrs` | `AttributeSet`: The attributes of the XML tag that is inflating the preference. <br /> |

**See also:**

- `https://developer.android.com/reference/android/preference/Preference#Preference(android.content.Context,%20android.util.AttributeSet,%20int)`

### Preference

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public Preference (Context context, 
                AttributeSet attrs, 
                int defStyleAttr)
```

Perform inflation from XML and apply a class-specific base style. This
constructor of Preference allows subclasses to use their own base style
when they are inflating. For example, a `https://developer.android.com/reference/android/preference/CheckBoxPreference`
constructor calls this version of the super class constructor and
supplies `android.R.attr.checkBoxPreferenceStyle` for
<var translate="no">defStyleAttr</var>. This allows the theme's checkbox preference
style to modify all of the base preference attributes as well as the
`https://developer.android.com/reference/android/preference/CheckBoxPreference` class's attributes.

<br />

| Parameters ||
|---|---|
| `context` | `Context`: The Context this is associated with, through which it can access the current theme, resources, `https://developer.android.com/reference/android/content/SharedPreferences`, etc. <br /> |
| `attrs` | `AttributeSet`: The attributes of the XML tag that is inflating the preference. <br /> |
| `defStyleAttr` | `int`: An attribute in the current theme that contains a reference to a style resource that supplies default values for the view. Can be 0 to not look for defaults. <br /> |

**See also:**

- `https://developer.android.com/reference/android/preference/Preference#Preference(android.content.Context,%20android.util.AttributeSet)`

### Preference

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public Preference (Context context, 
                AttributeSet attrs, 
                int defStyleAttr, 
                int defStyleRes)
```

Perform inflation from XML and apply a class-specific base style. This
constructor of Preference allows subclasses to use their own base style
when they are inflating. For example, a `https://developer.android.com/reference/android/preference/CheckBoxPreference`
constructor calls this version of the super class constructor and
supplies `android.R.attr.checkBoxPreferenceStyle` for
<var translate="no">defStyleAttr</var>. This allows the theme's checkbox preference
style to modify all of the base preference attributes as well as the
`https://developer.android.com/reference/android/preference/CheckBoxPreference` class's attributes.

<br />

| Parameters ||
|---|---|
| `context` | `Context`: The Context this is associated with, through which it can access the current theme, resources, `https://developer.android.com/reference/android/content/SharedPreferences`, etc. <br /> |
| `attrs` | `AttributeSet`: The attributes of the XML tag that is inflating the preference. <br /> |
| `defStyleAttr` | `int`: An attribute in the current theme that contains a reference to a style resource that supplies default values for the view. Can be 0 to not look for defaults. <br /> |
| `defStyleRes` | `int`: A resource identifier of a style resource that supplies default values for the view, used only if defStyleAttr is 0 or can not be found in the theme. Can be 0 to not look for defaults. <br /> |

**See also:**

- `https://developer.android.com/reference/android/preference/Preference#Preference(android.content.Context,%20android.util.AttributeSet)`

## Public methods

### compareTo

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int compareTo (Preference another)
```

Compares Preference objects based on order (if set), otherwise alphabetically on the titles.

<br />

| Parameters ||
|---|---|
| `another` | `Preference`: The Preference to compare to this one. <br /> |

| Returns ||
|---|---|
| `int` | 0 if the same; less than 0 if this Preference sorts ahead of <var translate="no">another</var>; greater than 0 if this Preference sorts after <var translate="no">another</var>. <br /> |

### getContext

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public Context getContext ()
```

Returns the `https://developer.android.com/reference/android/content/Context` of this Preference.
Each Preference in a Preference hierarchy can be
from different Context (for example, if multiple activities provide preferences into a single
`https://developer.android.com/reference/android/preference/PreferenceActivity`). This Context will be used to save the Preference values.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/content/Context` | The Context of this Preference. <br /> |

### getDependency

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public String getDependency ()
```

Returns the key of the dependency on this Preference.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | The key of the dependency. <br /> |

**See also:**

- `https://developer.android.com/reference/android/preference/Preference#setDependency(java.lang.String)`

### getEditor

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public SharedPreferences.Editor getEditor ()
```

Returns an `https://developer.android.com/reference/android/content/SharedPreferences.Editor` where this Preference can
save its value(s). Usually it's easier to use one of the helper save
methods: `https://developer.android.com/reference/android/preference/Preference#persistBoolean(boolean)`, `https://developer.android.com/reference/android/preference/Preference#persistFloat(float)`,
`https://developer.android.com/reference/android/preference/Preference#persistInt(int)`, `https://developer.android.com/reference/android/preference/Preference#persistLong(long)`,
`https://developer.android.com/reference/android/preference/Preference#persistString(java.lang.String)`. To read values, see
`https://developer.android.com/reference/android/preference/Preference#getSharedPreferences()`. If `https://developer.android.com/reference/android/preference/Preference#shouldCommit()` returns
true, it is this Preference's responsibility to commit.


In some cases, writes to this will not be committed right away and hence
not show up in the SharedPreferences, this is intended behavior to
improve performance.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/content/SharedPreferences.Editor` | a `https://developer.android.com/reference/android/content/SharedPreferences.Editor` where this preference saves its value(s). If this preference isn't attached to a Preference hierarchy or if a `https://developer.android.com/reference/android/preference/PreferenceDataStore` has been set, this method returns `null`. <br /> |

**See also:**

- `https://developer.android.com/reference/android/preference/Preference#shouldCommit()`
- `https://developer.android.com/reference/android/preference/Preference#getSharedPreferences()`
- `https://developer.android.com/reference/android/preference/Preference#setPreferenceDataStore(android.preference.PreferenceDataStore)`

### getExtras

Added in [API level 11](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)   
Deprecated in [API level
29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public Bundle getExtras ()
```

Return the extras Bundle object associated with this preference, creating
a new Bundle if there currently isn't one. You can use this to get and
set individual extra key/value pairs.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/os/Bundle` | <br /> |

### getFragment

Added in [API level 11](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)   
Deprecated in [API level
29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public String getFragment ()
```

Return the fragment class name associated with this Preference.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | The fragment class name last set via `https://developer.android.com/reference/android/preference/Preference#setFragment(java.lang.String)` or XML. <br /> |

### getIcon

Added in [API level 11](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)   
Deprecated in [API level
29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public Drawable getIcon ()
```

Returns the icon of this Preference.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/graphics/drawable/Drawable` | the icon <br /> |

**See also:**

- `https://developer.android.com/reference/android/preference/Preference#setIcon(android.graphics.drawable.Drawable)`

### getIntent

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public Intent getIntent ()
```

Return the `https://developer.android.com/reference/android/content/Intent` associated with this Preference.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/content/Intent` | The `https://developer.android.com/reference/android/content/Intent` last set via `https://developer.android.com/reference/android/preference/Preference#setIntent(android.content.Intent)` or XML. <br /> |

### getKey

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public String getKey ()
```

Gets the key for this Preference, which is also the key used for storing values into
`https://developer.android.com/reference/android/content/SharedPreferences` or `https://developer.android.com/reference/android/preference/PreferenceDataStore`.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | The key. <br /> |

### getLayoutResource

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int getLayoutResource ()
```

Gets the layout resource that will be shown as the `https://developer.android.com/reference/android/view/View` for this Preference.

<br />

| Returns ||
|---|---|
| `int` | The layout resource ID. <br /> |

### getOnPreferenceChangeListener

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public Preference.OnPreferenceChangeListener getOnPreferenceChangeListener ()
```

Returns the callback to be invoked when this Preference is changed by the
user (but before the internal state has been updated).

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/preference/Preference.OnPreferenceChangeListener` | The callback to be invoked. <br /> |

### getOnPreferenceClickListener

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public Preference.OnPreferenceClickListener getOnPreferenceClickListener ()
```

Returns the callback to be invoked when this Preference is clicked.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/preference/Preference.OnPreferenceClickListener` | The callback to be invoked. <br /> |

### getOrder

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int getOrder ()
```

Gets the order of this Preference with respect to other Preference objects on the same level.

<br />

| Returns ||
|---|---|
| `int` | the order of this Preference <br /> |

**See also:**

- `https://developer.android.com/reference/android/preference/Preference#setOrder(int)`

### getParent

Added in [API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)   
Deprecated in [API level
29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public PreferenceGroup getParent ()
```

Returns the `https://developer.android.com/reference/android/preference/PreferenceGroup` which is this Preference assigned to or `null` if
this preference is not assigned to any group or is a root Preference.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/preference/PreferenceGroup` | the parent PreferenceGroup or `null` if not attached to any <br /> |

### getPersistedStringSet

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)   
Deprecated in [API level
29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public Set<String> getPersistedStringSet (Set<String> defaultReturnValue)
```

Attempts to get a persisted set of Strings if this Preference is persistent.

<br />

| Parameters ||
|---|---|
| `defaultReturnValue` | `Set`: The default value to return if either this Preference is not persistent or this Preference is not present. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/Set<https://developer.android.com/reference/java/lang/String>` | The value from the data store or the default return value. <br /> |

**See also:**

- `https://developer.android.com/reference/android/preference/Preference#persistStringSet(java.util.Set<java.lang.String>)`

### getPreferenceDataStore

Added in [API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)   
Deprecated in [API level
29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public PreferenceDataStore getPreferenceDataStore ()
```

Returns `https://developer.android.com/reference/android/preference/PreferenceDataStore` used by this Preference. Returns `null` if
`https://developer.android.com/reference/android/content/SharedPreferences` is used instead.

By default preferences always use `https://developer.android.com/reference/android/content/SharedPreferences`. To make this
preference to use the `https://developer.android.com/reference/android/preference/PreferenceDataStore` you need to assign your implementation
to the Preference itself via `https://developer.android.com/reference/android/preference/Preference#setPreferenceDataStore(android.preference.PreferenceDataStore)` or to its
`https://developer.android.com/reference/android/preference/PreferenceManager` via
`https://developer.android.com/reference/android/preference/PreferenceManager#setPreferenceDataStore(android.preference.PreferenceDataStore)`.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/preference/PreferenceDataStore` | The `https://developer.android.com/reference/android/preference/PreferenceDataStore` used by this Preference or `null` if none. <br /> |

### getPreferenceManager

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public PreferenceManager getPreferenceManager ()
```

Gets the `https://developer.android.com/reference/android/preference/PreferenceManager` that manages this Preference object's tree.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/preference/PreferenceManager` | The `https://developer.android.com/reference/android/preference/PreferenceManager`. <br /> |

### getSharedPreferences

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public SharedPreferences getSharedPreferences ()
```

Returns the `https://developer.android.com/reference/android/content/SharedPreferences` where this Preference can read its
value(s). Usually, it's easier to use one of the helper read methods:
`https://developer.android.com/reference/android/preference/Preference#getPersistedBoolean(boolean)`, `https://developer.android.com/reference/android/preference/Preference#getPersistedFloat(float)`,
`https://developer.android.com/reference/android/preference/Preference#getPersistedInt(int)`, `https://developer.android.com/reference/android/preference/Preference#getPersistedLong(long)`,
`https://developer.android.com/reference/android/preference/Preference#getPersistedString(java.lang.String)`. To save values, see
`https://developer.android.com/reference/android/preference/Preference#getEditor()`.


In some cases, writes to the `https://developer.android.com/reference/android/preference/Preference#getEditor()` will not be committed
right away and hence not show up in the returned
`https://developer.android.com/reference/android/content/SharedPreferences`, this is intended behavior to improve
performance.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/content/SharedPreferences` | the `https://developer.android.com/reference/android/content/SharedPreferences` where this Preference reads its value(s). If this preference isn't attached to a Preference hierarchy or if a `https://developer.android.com/reference/android/preference/PreferenceDataStore` has been set, this method returns `null`. <br /> |

**See also:**

- `https://developer.android.com/reference/android/preference/Preference#getEditor()`
- `https://developer.android.com/reference/android/preference/Preference#setPreferenceDataStore(android.preference.PreferenceDataStore)`

### getShouldDisableView

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean getShouldDisableView ()
```

Checks whether this Preference should disable its view when it's action is disabled.

<br />

| Returns ||
|---|---|
| `boolean` | `true` if it should disable the view <br /> |

**See also:**

- `https://developer.android.com/reference/android/preference/Preference#setShouldDisableView(boolean)`

### getSummary

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public CharSequence getSummary ()
```

Returns the summary of this Preference.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/CharSequence` | the summary <br /> |

**See also:**

- `https://developer.android.com/reference/android/preference/Preference#setSummary(java.lang.CharSequence)`

### getTitle

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public CharSequence getTitle ()
```

Returns the title of this Preference.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/CharSequence` | the title <br /> |

**See also:**

- `https://developer.android.com/reference/android/preference/Preference#setTitle(java.lang.CharSequence)`

### getTitleRes

Added in [API level 14](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)   
Deprecated in [API level
29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int getTitleRes ()
```

Returns the title resource ID of this Preference. If the title did not come from a resource,
`0` is returned.

<br />

| Returns ||
|---|---|
| `int` | the title resource <br /> |

**See also:**

- `https://developer.android.com/reference/android/preference/Preference#setTitle(int)`

### getView

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public View getView (View convertView, 
                ViewGroup parent)
```

Gets the View that will be shown in the `https://developer.android.com/reference/android/preference/PreferenceActivity`.

<br />

| Parameters ||
|---|---|
| `convertView` | `View`: The old View to reuse, if possible. Note: You should check that this View is non-null and of an appropriate type before using. If it is not possible to convert this View to display the correct data, this method can create a new View. <br /> |
| `parent` | `ViewGroup`: The parent that this View will eventually be attached to. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/view/View` | Returns the same Preference object, for chaining multiple calls into a single statement. <br /> |

**See also:**

- `https://developer.android.com/reference/android/preference/Preference#onCreateView(android.view.ViewGroup)`
- `https://developer.android.com/reference/android/preference/Preference#onBindView(android.view.View)`

### getWidgetLayoutResource

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int getWidgetLayoutResource ()
```

Gets the layout resource for the controllable widget portion of this Preference.

<br />

| Returns ||
|---|---|
| `int` | The layout resource ID. <br /> |

### hasKey

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean hasKey ()
```

Checks whether this Preference has a valid key.

<br />

| Returns ||
|---|---|
| `boolean` | True if the key exists and is not a blank string, false otherwise. <br /> |

### isEnabled

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean isEnabled ()
```

Checks whether this Preference should be enabled in the list.

<br />

| Returns ||
|---|---|
| `boolean` | `true` if this Preference is enabled, false otherwise <br /> |

### isIconSpaceReserved

Added in [API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)   
Deprecated in [API level
29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean isIconSpaceReserved ()
```

Gets whether the space this preference icon view is reserved.

<br />

| Returns ||
|---|---|
| `boolean` | `true` if the space of this preference icon view is reserved <br /> |

**See also:**

- `https://developer.android.com/reference/android/preference/Preference#setIconSpaceReserved(boolean)`

### isPersistent

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean isPersistent ()
```

Checks whether this Preference is persistent. If it is, it stores its value(s) into
the persistent `https://developer.android.com/reference/android/content/SharedPreferences` storage by default or into
`https://developer.android.com/reference/android/preference/PreferenceDataStore` if assigned.

<br />

| Returns ||
|---|---|
| `boolean` | True if it is persistent. <br /> |

### isRecycleEnabled

Added in [API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)   
Deprecated in [API level
29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean isRecycleEnabled ()
```

Checks whether this Preference has enabled to have its view recycled when used in the list
view.

<br />

| Returns ||
|---|---|
| `boolean` | `true` if this preference view should be recycled <br /> |

**See also:**

- `https://developer.android.com/reference/android/preference/Preference#setRecycleEnabled(boolean)`

### isSelectable

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean isSelectable ()
```

Checks whether this Preference should be selectable in the list.

<br />

| Returns ||
|---|---|
| `boolean` | `true` if it is selectable, `false` otherwise <br /> |

### isSingleLineTitle

Added in [API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)   
Deprecated in [API level
29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean isSingleLineTitle ()
```

Gets whether the title of this preference is constrained to a single line.

<br />

| Returns ||
|---|---|
| `boolean` | `true` if the title of this preference is constrained to a single line <br /> |

**See also:**

- `https://developer.android.com/reference/android/preference/Preference#setSingleLineTitle(boolean)`

### notifyDependencyChange

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void notifyDependencyChange (boolean disableDependents)
```

Notifies any listening dependents of a change that affects the
dependency.

<br />

| Parameters ||
|---|---|
| `disableDependents` | `boolean`: Whether this Preference should disable its dependents. <br /> |

### onDependencyChanged

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void onDependencyChanged (Preference dependency, 
                boolean disableDependent)
```

Called when the dependency changes.

<br />

| Parameters ||
|---|---|
| `dependency` | `Preference`: The Preference that this Preference depends on. <br /> |
| `disableDependent` | `boolean`: Set true to disable this Preference. <br /> |

### onParentChanged

Added in [API level 19](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)   
Deprecated in [API level
29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void onParentChanged (Preference parent, 
                boolean disableChild)
```

Called when the implicit parent dependency changes.

<br />

| Parameters ||
|---|---|
| `parent` | `Preference`: The Preference that this Preference depends on. <br /> |
| `disableChild` | `boolean`: Set true to disable this Preference. <br /> |

### peekExtras

Added in [API level 11](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)   
Deprecated in [API level
29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public Bundle peekExtras ()
```

Return the extras Bundle object associated with this preference, returning `null` if
there is not currently one.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/os/Bundle` | <br /> |

### persistStringSet

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)   
Deprecated in [API level
29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean persistStringSet (Set<String> values)
```

Attempts to persist a set of Strings if this Preference is persistent.

<br />

| Parameters ||
|---|---|
| `values` | `Set`: The values to persist. <br /> |

| Returns ||
|---|---|
| `boolean` | True if this Preference is persistent. (This is not whether the value was persisted, since we may not necessarily commit if there will be a batch commit later.) <br /> |

**See also:**

- `https://developer.android.com/reference/android/preference/Preference#getPersistedStringSet(java.util.Set<java.lang.String>)`

### restoreHierarchyState

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void restoreHierarchyState (Bundle container)
```

Restore this Preference hierarchy's previously saved state from the given container.

<br />

| Parameters ||
|---|---|
| `container` | `Bundle`: The Bundle that holds the previously saved state. <br /> |

**See also:**

- `https://developer.android.com/reference/android/preference/Preference#saveHierarchyState(android.os.Bundle)`
- `https://developer.android.com/reference/android/preference/Preference#onRestoreInstanceState(android.os.Parcelable)`

### saveHierarchyState

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void saveHierarchyState (Bundle container)
```

Store this Preference hierarchy's frozen state into the given container.

<br />

| Parameters ||
|---|---|
| `container` | `Bundle`: The Bundle in which to save the instance of this Preference. <br /> |

**See also:**

- `https://developer.android.com/reference/android/preference/Preference#restoreHierarchyState(android.os.Bundle)`
- `https://developer.android.com/reference/android/preference/Preference#onSaveInstanceState()`

### setDefaultValue

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void setDefaultValue (Object defaultValue)
```

Sets the default value for this Preference, which will be set either if
persistence is off or persistence is on and the preference is not found
in the persistent storage.

<br />

| Parameters ||
|---|---|
| `defaultValue` | `Object`: The default value. <br /> |

### setDependency

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void setDependency (String dependencyKey)
```

Sets the key of a Preference that this Preference will depend on. If that
Preference is not set or is off, this Preference will be disabled.

<br />

| Parameters ||
|---|---|
| `dependencyKey` | `String`: The key of the Preference that this depends on. <br /> |

### setEnabled

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void setEnabled (boolean enabled)
```

Sets whether this Preference is enabled. If disabled, it will
not handle clicks.

<br />

| Parameters ||
|---|---|
| `enabled` | `boolean`: set `true` to enable it <br /> |

### setFragment

Added in [API level 11](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)   
Deprecated in [API level
29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void setFragment (String fragment)
```

Sets the class name of a fragment to be shown when this Preference is clicked.

<br />

| Parameters ||
|---|---|
| `fragment` | `String`: The class name of the fragment associated with this Preference. <br /> |

### setIcon

Added in [API level 11](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)   
Deprecated in [API level
29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void setIcon (Drawable icon)
```

Sets the icon for this Preference with a Drawable. This icon will be placed into the ID
`https://developer.android.com/reference/android/R.id#icon` within the View created by `https://developer.android.com/reference/android/preference/Preference#onCreateView(android.view.ViewGroup)`.

<br />

| Parameters ||
|---|---|
| `icon` | `Drawable`: the optional icon for this Preference <br /> |

### setIcon

Added in [API level 11](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)   
Deprecated in [API level
29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void setIcon (int iconResId)
```

Sets the icon for this Preference with a resource ID.

<br />

| Parameters ||
|---|---|
| `iconResId` | `int`: the icon as a resource ID <br /> |

**See also:**

- `https://developer.android.com/reference/android/preference/Preference#setIcon(android.graphics.drawable.Drawable)`

### setIconSpaceReserved

Added in [API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)   
Deprecated in [API level
29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void setIconSpaceReserved (boolean iconSpaceReserved)
```

Sets whether to reserve the space of this Preference icon view when no icon is provided.

<br />

| Parameters ||
|---|---|
| `iconSpaceReserved` | `boolean`: set `true` if the space for the icon view should be reserved <br /> |

### setIntent

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void setIntent (Intent intent)
```

Sets an `https://developer.android.com/reference/android/content/Intent` to be used for
`https://developer.android.com/reference/android/content/Context#startActivity(android.content.Intent)` when this Preference is clicked.

<br />

| Parameters ||
|---|---|
| `intent` | `Intent`: The intent associated with this Preference. <br /> |

### setKey

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void setKey (String key)
```

Sets the key for this Preference, which is used as a key to the `https://developer.android.com/reference/android/content/SharedPreferences` or
`https://developer.android.com/reference/android/preference/PreferenceDataStore`. This should be unique for the package.

<br />

| Parameters ||
|---|---|
| `key` | `String`: The key for the preference. <br /> |

### setLayoutResource

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void setLayoutResource (int layoutResId)
```

Sets the layout resource that is inflated as the `https://developer.android.com/reference/android/view/View` to be shown
for this Preference. In most cases, the default layout is sufficient for
custom Preference objects and only the widget layout needs to be changed.


This layout should contain a `https://developer.android.com/reference/android/view/ViewGroup` with ID
`https://developer.android.com/reference/android/R.id#widget_frame` to be the parent of the specific widget
for this Preference. It should similarly contain
`https://developer.android.com/reference/android/R.id#title` and `https://developer.android.com/reference/android/R.id#summary`.

<br />

| Parameters ||
|---|---|
| `layoutResId` | `int`: The layout resource ID to be inflated and returned as a `https://developer.android.com/reference/android/view/View`. <br /> |

**See also:**

- `https://developer.android.com/reference/android/preference/Preference#setWidgetLayoutResource(int)`

### setOnPreferenceChangeListener

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void setOnPreferenceChangeListener (Preference.OnPreferenceChangeListener onPreferenceChangeListener)
```

Sets the callback to be invoked when this Preference is changed by the
user (but before the internal state has been updated).

<br />

| Parameters ||
|---|---|
| `onPreferenceChangeListener` | `Preference.OnPreferenceChangeListener`: The callback to be invoked. <br /> |

### setOnPreferenceClickListener

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void setOnPreferenceClickListener (Preference.OnPreferenceClickListener onPreferenceClickListener)
```

Sets the callback to be invoked when this Preference is clicked.

<br />

| Parameters ||
|---|---|
| `onPreferenceClickListener` | `Preference.OnPreferenceClickListener`: The callback to be invoked. <br /> |

### setOrder

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void setOrder (int order)
```

Sets the order of this Preference with respect to other Preference objects on the same level.
If this is not specified, the default behavior is to sort alphabetically. The
`https://developer.android.com/reference/android/preference/PreferenceGroup#setOrderingAsAdded(boolean)` can be used to order Preference objects
based on the order they appear in the XML.

<br />

| Parameters ||
|---|---|
| `order` | `int`: the order for this Preference. A lower value will be shown first. Use `https://developer.android.com/reference/android/preference/Preference#DEFAULT_ORDER` to sort alphabetically or allow ordering from XML <br /> |

**See also:**

- `https://developer.android.com/reference/android/preference/PreferenceGroup#setOrderingAsAdded(boolean)`
- `https://developer.android.com/reference/android/preference/Preference#DEFAULT_ORDER`

### setPersistent

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void setPersistent (boolean persistent)
```

Sets whether this Preference is persistent. When persistent, it stores its value(s) into
the persistent `https://developer.android.com/reference/android/content/SharedPreferences` storage by default or into
`https://developer.android.com/reference/android/preference/PreferenceDataStore` if assigned.

<br />

| Parameters ||
|---|---|
| `persistent` | `boolean`: set `true` if it should store its value(s) into the storage. <br /> |

### setPreferenceDataStore

Added in [API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)   
Deprecated in [API level
29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

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

Sets a `https://developer.android.com/reference/android/preference/PreferenceDataStore` to be used by this Preference instead of using
`https://developer.android.com/reference/android/content/SharedPreferences`.

The data store will remain assigned even if the Preference is moved around the preference
hierarchy. It will also override a data store propagated from the `https://developer.android.com/reference/android/preference/PreferenceManager`
that owns this Preference.

<br />

| Parameters ||
|---|---|
| `dataStore` | `PreferenceDataStore`: The `https://developer.android.com/reference/android/preference/PreferenceDataStore` to be used by this Preference. <br /> |

**See also:**

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

### setRecycleEnabled

Added in [API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)   
Deprecated in [API level
29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void setRecycleEnabled (boolean enabled)
```

Sets whether this Preference has enabled to have its view recycled when used in the list
view. By default the recycling is enabled.

The value can be changed only before this preference is added to the preference hierarchy.

If view recycling is not allowed then each time the list view populates this preference
the `https://developer.android.com/reference/android/preference/Preference#getView(android.view.View,%20android.view.ViewGroup)` method receives a `null` convert view and needs
to recreate the view. Otherwise view gets recycled and only `https://developer.android.com/reference/android/preference/Preference#onBindView(android.view.View)` gets
called.


If you override this method you *must* call through to the
superclass implementation.

<br />

| Parameters ||
|---|---|
| `enabled` | `boolean`: set `true` if this preference view should be recycled <br /> |

### setSelectable

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void setSelectable (boolean selectable)
```

Sets whether this Preference is selectable.

<br />

| Parameters ||
|---|---|
| `selectable` | `boolean`: set `true` to make it selectable <br /> |

### setShouldDisableView

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void setShouldDisableView (boolean shouldDisableView)
```

Sets whether this Preference should disable its view when it gets disabled.

For example, set this and `https://developer.android.com/reference/android/preference/Preference#setEnabled(boolean)` to false for preferences that are
only displaying information and 1) should not be clickable 2) should not have the view set to
the disabled state.

<br />

| Parameters ||
|---|---|
| `shouldDisableView` | `boolean`: set `true` if this preference should disable its view when the preference is disabled <br /> |

### setSingleLineTitle

Added in [API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)   
Deprecated in [API level
29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void setSingleLineTitle (boolean singleLineTitle)
```

Sets whether to constrain the title of this Preference to a single line instead of
letting it wrap onto multiple lines.

<br />

| Parameters ||
|---|---|
| `singleLineTitle` | `boolean`: set `true` if the title should be constrained to one line <br /> |

### setSummary

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void setSummary (CharSequence summary)
```

Sets the summary for this Preference with a CharSequence.

<br />

| Parameters ||
|---|---|
| `summary` | `CharSequence`: the summary for the preference <br /> |

### setSummary

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void setSummary (int summaryResId)
```

Sets the summary for this Preference with a resource ID.

<br />

| Parameters ||
|---|---|
| `summaryResId` | `int`: the summary as a resource <br /> |

**See also:**

- `https://developer.android.com/reference/android/preference/Preference#setSummary(java.lang.CharSequence)`

### setTitle

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void setTitle (CharSequence title)
```

Sets the title for this Preference with a CharSequence. This title will be placed into the ID
`https://developer.android.com/reference/android/R.id#title` within the View created by `https://developer.android.com/reference/android/preference/Preference#onCreateView(android.view.ViewGroup)`.

<br />

| Parameters ||
|---|---|
| `title` | `CharSequence`: the title for this Preference <br /> |

### setTitle

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void setTitle (int titleResId)
```

Sets the title for this Preference with a resource ID.

<br />

| Parameters ||
|---|---|
| `titleResId` | `int`: the title as a resource ID <br /> |

**See also:**

- `https://developer.android.com/reference/android/preference/Preference#setTitle(java.lang.CharSequence)`

### setWidgetLayoutResource

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void setWidgetLayoutResource (int widgetLayoutResId)
```

Sets the layout for the controllable widget portion of this Preference. This
is inflated into the main layout. For example, a `https://developer.android.com/reference/android/preference/CheckBoxPreference`
would specify a custom layout (consisting of just the CheckBox) here,
instead of creating its own main layout.

<br />

| Parameters ||
|---|---|
| `widgetLayoutResId` | `int`: The layout resource ID to be inflated into the main layout. <br /> |

**See also:**

- `https://developer.android.com/reference/android/preference/Preference#setLayoutResource(int)`

### shouldCommit

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean shouldCommit ()
```

Returns whether the `https://developer.android.com/reference/android/preference/Preference` should commit its saved value(s) in
`https://developer.android.com/reference/android/preference/Preference#getEditor()`. This may return false in situations where batch
committing is being done (by the manager) to improve performance.

If this preference is using `https://developer.android.com/reference/android/preference/PreferenceDataStore` this value is irrelevant.

<br />

| Returns ||
|---|---|
| `boolean` | Whether the Preference should commit its saved value(s). <br /> |

**See also:**

- `https://developer.android.com/reference/android/preference/Preference#getEditor()`

### shouldDisableDependents

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean shouldDisableDependents ()
```

Checks whether this preference's dependents should currently be
disabled.

<br />

| Returns ||
|---|---|
| `boolean` | True if the dependents should be disabled, otherwise false. <br /> |

### toString

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public String toString ()
```

Returns a string representation of the object.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | a string representation of the object. <br /> |

## Protected methods

### callChangeListener

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
protected boolean callChangeListener (Object newValue)
```

Call this method after the user changes the preference, but before the
internal state is set. This allows the client to ignore the user value.

<br />

| Parameters ||
|---|---|
| `newValue` | `Object`: The new value of this Preference. <br /> |

| Returns ||
|---|---|
| `boolean` | True if the user value should be set as the preference value (and persisted). <br /> |

### findPreferenceInHierarchy

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
protected Preference findPreferenceInHierarchy (String key)
```

Finds a Preference in this hierarchy (the whole thing,
even above/below your `https://developer.android.com/reference/android/preference/PreferenceScreen` screen break) with the given
key.


This only functions after we have been attached to a hierarchy.

<br />

| Parameters ||
|---|---|
| `key` | `String`: The key of the Preference to find. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/preference/Preference` | The Preference that uses the given key. <br /> |

### getPersistedBoolean

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
protected boolean getPersistedBoolean (boolean defaultReturnValue)
```

Attempts to get a persisted boolean if this Preference is persistent.

<br />

| Parameters ||
|---|---|
| `defaultReturnValue` | `boolean`: The default value to return if either this Preference is not persistent or this Preference is not present. <br /> |

| Returns ||
|---|---|
| `boolean` | The value from the data store or the default return value. <br /> |

**See also:**

- `https://developer.android.com/reference/android/preference/Preference#getPersistedString(java.lang.String)`
- `https://developer.android.com/reference/android/preference/Preference#persistBoolean(boolean)`

### getPersistedFloat

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
protected float getPersistedFloat (float defaultReturnValue)
```

Attempts to get a persisted float if this Preference is persistent.

<br />

| Parameters ||
|---|---|
| `defaultReturnValue` | `float`: The default value to return if either this Preference is not persistent or this Preference is not present. <br /> |

| Returns ||
|---|---|
| `float` | The value from the data store or the default return value. <br /> |

**See also:**

- `https://developer.android.com/reference/android/preference/Preference#getPersistedString(java.lang.String)`
- `https://developer.android.com/reference/android/preference/Preference#persistFloat(float)`

### getPersistedInt

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
protected int getPersistedInt (int defaultReturnValue)
```

Attempts to get a persisted int if this Preference is persistent.

<br />

| Parameters ||
|---|---|
| `defaultReturnValue` | `int`: The default value to return if either this Preference is not persistent or this Preference is not present. <br /> |

| Returns ||
|---|---|
| `int` | The value from the data store or the default return value. <br /> |

**See also:**

- `https://developer.android.com/reference/android/preference/Preference#getPersistedString(java.lang.String)`
- `https://developer.android.com/reference/android/preference/Preference#persistInt(int)`

### getPersistedLong

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
protected long getPersistedLong (long defaultReturnValue)
```

Attempts to get a persisted long if this Preference is persistent.

<br />

| Parameters ||
|---|---|
| `defaultReturnValue` | `long`: The default value to return if either this Preference is not persistent or this Preference is not present. <br /> |

| Returns ||
|---|---|
| `long` | The value from the data store or the default return value. <br /> |

**See also:**

- `https://developer.android.com/reference/android/preference/Preference#getPersistedString(java.lang.String)`
- `https://developer.android.com/reference/android/preference/Preference#persistLong(long)`

### getPersistedString

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
protected String getPersistedString (String defaultReturnValue)
```

Attempts to get a persisted String if this Preference is persistent.

<br />

| Parameters ||
|---|---|
| `defaultReturnValue` | `String`: The default value to return if either this Preference is not persistent or this Preference is not present. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | The value from the data store or the default return value. <br /> |

**See also:**

- `https://developer.android.com/reference/android/preference/Preference#persistString(java.lang.String)`

### notifyChanged

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
protected void notifyChanged ()
```

Should be called when the data of this `https://developer.android.com/reference/android/preference/Preference` has changed.

<br />

### notifyHierarchyChanged

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
protected void notifyHierarchyChanged ()
```

Should be called when a Preference has been
added/removed from this group, or the ordering should be
re-evaluated.

<br />

### onAttachedToActivity

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
protected void onAttachedToActivity ()
```

Called when the Preference hierarchy has been attached to the
`https://developer.android.com/reference/android/preference/PreferenceActivity`. This can also be called when this
Preference has been attached to a group that was already attached
to the `https://developer.android.com/reference/android/preference/PreferenceActivity`.

<br />

### onAttachedToHierarchy

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
protected void onAttachedToHierarchy (PreferenceManager preferenceManager)
```

Called when this Preference has been attached to a Preference hierarchy.
Make sure to call the super implementation.

<br />

| Parameters ||
|---|---|
| `preferenceManager` | `PreferenceManager`: The PreferenceManager of the hierarchy. <br /> |

### onBindView

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
protected void onBindView (View view)
```

Binds the created View to the data for this Preference.


This is a good place to grab references to custom Views in the layout and
set properties on them.


Make sure to call through to the superclass's implementation.


If you override this method you *must* call through to the
superclass implementation.

<br />

| Parameters ||
|---|---|
| `view` | `View`: The View that shows this Preference. <br /> |

**See also:**

- `https://developer.android.com/reference/android/preference/Preference#onCreateView(android.view.ViewGroup)`

### onClick

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
protected void onClick ()
```

Processes a click on the preference. This includes saving the value to
the `https://developer.android.com/reference/android/content/SharedPreferences`. However, the overridden method should
call `https://developer.android.com/reference/android/preference/Preference#callChangeListener(java.lang.Object)` to make sure the client wants to
update the preference's state with the new value.

<br />

### onCreateView

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
protected View onCreateView (ViewGroup parent)
```

Creates the View to be shown for this Preference in the
`https://developer.android.com/reference/android/preference/PreferenceActivity`. The default behavior is to inflate the main
layout of this Preference (see `https://developer.android.com/reference/android/preference/Preference#setLayoutResource(int)`. If
changing this behavior, please specify a `https://developer.android.com/reference/android/view/ViewGroup` with ID
`https://developer.android.com/reference/android/R.id#widget_frame`.


Make sure to call through to the superclass's implementation.


If you override this method you *must* call through to the
superclass implementation.

<br />

| Parameters ||
|---|---|
| `parent` | `ViewGroup`: The parent that this View will eventually be attached to. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/view/View` | The View that displays this Preference. <br /> |

**See also:**

- `https://developer.android.com/reference/android/preference/Preference#onBindView(android.view.View)`

### onGetDefaultValue

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
protected Object onGetDefaultValue (TypedArray a, 
                int index)
```

Called when a Preference is being inflated and the default value
attribute needs to be read. Since different Preference types have
different value types, the subclass should get and return the default
value which will be its value type.


For example, if the value type is String, the body of the method would
proxy to `https://developer.android.com/reference/android/content/res/TypedArray#getString(int)`.

<br />

| Parameters ||
|---|---|
| `a` | `TypedArray`: The set of attributes. <br /> |
| `index` | `int`: The index of the default value attribute. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/Object` | The default value of this preference type. <br /> |

### onPrepareForRemoval

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
protected void onPrepareForRemoval ()
```

Called when this Preference is being removed from the hierarchy. You
should remove any references to this Preference that you know about. Make
sure to call through to the superclass implementation.


If you override this method you *must* call through to the
superclass implementation.

<br />

### onRestoreInstanceState

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
protected void onRestoreInstanceState (Parcelable state)
```

Hook allowing a Preference to re-apply a representation of its internal state that had
previously been generated by `https://developer.android.com/reference/android/preference/Preference#onSaveInstanceState()`. This function will never be called
with a `null` state.

<br />

| Parameters ||
|---|---|
| `state` | `Parcelable`: The saved state that had previously been returned by `https://developer.android.com/reference/android/preference/Preference#onSaveInstanceState()`. <br /> |

**See also:**

- `https://developer.android.com/reference/android/preference/Preference#onSaveInstanceState()`
- `https://developer.android.com/reference/android/preference/Preference#restoreHierarchyState(android.os.Bundle)`

### onSaveInstanceState

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
protected Parcelable onSaveInstanceState ()
```

Hook allowing a Preference to generate a representation of its internal
state that can later be used to create a new instance with that same
state. This state should only contain information that is not persistent
or can be reconstructed later.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/os/Parcelable` | A Parcelable object containing the current dynamic state of this Preference, or `null` if there is nothing interesting to save. The default implementation returns `null`. <br /> |

**See also:**

- `https://developer.android.com/reference/android/preference/Preference#onRestoreInstanceState(android.os.Parcelable)`
- `https://developer.android.com/reference/android/preference/Preference#saveHierarchyState(android.os.Bundle)`

### onSetInitialValue

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
protected void onSetInitialValue (boolean restorePersistedValue, 
                Object defaultValue)
```

Implement this to set the initial value of the Preference.

If <var translate="no">restorePersistedValue</var> is true, you should restore the
Preference value from the `https://developer.android.com/reference/android/content/SharedPreferences`. If
<var translate="no">restorePersistedValue</var> is false, you should set the Preference
value to defaultValue that is given (and possibly store to SharedPreferences
if `https://developer.android.com/reference/android/preference/Preference#shouldPersist()` is true).

In case of using `https://developer.android.com/reference/android/preference/PreferenceDataStore`, the <var translate="no">restorePersistedValue</var> is
always `true`. But the default value (if provided) is set.

This may not always be called. One example is if it should not persist
but there is no default value given.

<br />

| Parameters ||
|---|---|
| `restorePersistedValue` | `boolean`: True to restore the persisted value; false to use the given <var translate="no">defaultValue</var>. <br /> |
| `defaultValue` | `Object`: The default value for this Preference. Only use this if <var translate="no">restorePersistedValue</var> is false. <br /> |

### persistBoolean

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
protected boolean persistBoolean (boolean value)
```

Attempts to persist a boolean if this Preference is persistent.

<br />

| Parameters ||
|---|---|
| `value` | `boolean`: The value to persist. <br /> |

| Returns ||
|---|---|
| `boolean` | True if this Preference is persistent. (This is not whether the value was persisted, since we may not necessarily commit if there will be a batch commit later.) <br /> |

**See also:**

- `https://developer.android.com/reference/android/preference/Preference#persistString(java.lang.String)`
- `https://developer.android.com/reference/android/preference/Preference#getPersistedBoolean(boolean)`

### persistFloat

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
protected boolean persistFloat (float value)
```

Attempts to persist a long if this Preference is persistent.

<br />

| Parameters ||
|---|---|
| `value` | `float`: The value to persist. <br /> |

| Returns ||
|---|---|
| `boolean` | True if this Preference is persistent. (This is not whether the value was persisted, since we may not necessarily commit if there will be a batch commit later.) <br /> |

**See also:**

- `https://developer.android.com/reference/android/preference/Preference#persistString(java.lang.String)`
- `https://developer.android.com/reference/android/preference/Preference#getPersistedFloat(float)`

### persistInt

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
protected boolean persistInt (int value)
```

Attempts to persist an int if this Preference is persistent.

<br />

| Parameters ||
|---|---|
| `value` | `int`: The value to persist. <br /> |

| Returns ||
|---|---|
| `boolean` | True if this Preference is persistent. (This is not whether the value was persisted, since we may not necessarily commit if there will be a batch commit later.) <br /> |

**See also:**

- `https://developer.android.com/reference/android/preference/Preference#persistString(java.lang.String)`
- `https://developer.android.com/reference/android/preference/Preference#getPersistedInt(int)`

### persistLong

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
protected boolean persistLong (long value)
```

Attempts to persist a long if this Preference is persistent.

<br />

| Parameters ||
|---|---|
| `value` | `long`: The value to persist. <br /> |

| Returns ||
|---|---|
| `boolean` | True if this Preference is persistent. (This is not whether the value was persisted, since we may not necessarily commit if there will be a batch commit later.) <br /> |

**See also:**

- `https://developer.android.com/reference/android/preference/Preference#persistString(java.lang.String)`
- `https://developer.android.com/reference/android/preference/Preference#getPersistedLong(long)`

### persistString

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
protected boolean persistString (String value)
```

Attempts to persist a String if this Preference is persistent.

<br />

| Parameters ||
|---|---|
| `value` | `String`: The value to persist. <br /> |

| Returns ||
|---|---|
| `boolean` | True if this Preference is persistent. (This is not whether the value was persisted, since we may not necessarily commit if there will be a batch commit later.) <br /> |

**See also:**

- `https://developer.android.com/reference/android/preference/Preference#getPersistedString(java.lang.String)`

### shouldPersist

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
protected boolean shouldPersist ()
```

Checks whether, at the given time this method is called, this Preference should store/restore
its value(s) into the `https://developer.android.com/reference/android/content/SharedPreferences` or into `https://developer.android.com/reference/android/preference/PreferenceDataStore` if
assigned. This, at minimum, checks whether this Preference is persistent and it currently has
a key. Before you save/restore from the storage, check this first.

<br />

| Returns ||
|---|---|
| `boolean` | True if it should persist the value. <br /> |