# Preference

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

*** ** * ** ***


```
class Preference : Comparable<Preference!>
```

<br />

Known direct subclasses [DialogPreference](https://developer.android.com/reference/kotlin/androidx/preference/DialogPreference), [PreferenceGroup](https://developer.android.com/reference/kotlin/androidx/preference/PreferenceGroup), [SeekBarPreference](https://developer.android.com/reference/kotlin/androidx/preference/SeekBarPreference), [TwoStatePreference](https://developer.android.com/reference/kotlin/androidx/preference/TwoStatePreference)

|---|---|
| `https://developer.android.com/reference/kotlin/androidx/preference/DialogPreference` | A base class for `https://developer.android.com/reference/kotlin/androidx/preference/Preference`s that are dialog-based. |
| `https://developer.android.com/reference/kotlin/androidx/preference/PreferenceGroup` | A container for multiple `https://developer.android.com/reference/kotlin/androidx/preference/Preference`s. |
| `https://developer.android.com/reference/kotlin/androidx/preference/SeekBarPreference` | Preference based on android.preference.SeekBarPreference but uses support preference as a base . |
| `https://developer.android.com/reference/kotlin/androidx/preference/TwoStatePreference` | Common base class for preferences that have two selectable states, save a boolean value, and may have dependent preferences that are enabled/disabled based on the current state. |

Known indirect subclasses [CheckBoxPreference](https://developer.android.com/reference/kotlin/androidx/preference/CheckBoxPreference), [DropDownPreference](https://developer.android.com/reference/kotlin/androidx/preference/DropDownPreference), [EditTextPreference](https://developer.android.com/reference/kotlin/androidx/preference/EditTextPreference), [ListPreference](https://developer.android.com/reference/kotlin/androidx/preference/ListPreference), [MultiSelectListPreference](https://developer.android.com/reference/kotlin/androidx/preference/MultiSelectListPreference), [PreferenceCategory](https://developer.android.com/reference/kotlin/androidx/preference/PreferenceCategory), [PreferenceScreen](https://developer.android.com/reference/kotlin/androidx/preference/PreferenceScreen), [SwitchPreferenceCompat](https://developer.android.com/reference/kotlin/androidx/preference/SwitchPreferenceCompat), [SwitchPreference](https://developer.android.com/reference/kotlin/androidx/preference/SwitchPreference)

|---|---|
| `https://developer.android.com/reference/kotlin/androidx/preference/CheckBoxPreference` | A `https://developer.android.com/reference/kotlin/androidx/preference/Preference` that provides checkbox widget functionality. |
| `https://developer.android.com/reference/kotlin/androidx/preference/DropDownPreference` | A `https://developer.android.com/reference/kotlin/androidx/preference/ListPreference` that presents the options in a drop down menu rather than a dialog. |
| `https://developer.android.com/reference/kotlin/androidx/preference/EditTextPreference` | A `https://developer.android.com/reference/kotlin/androidx/preference/DialogPreference` that shows a `https://developer.android.com/reference/android/widget/EditText.html` in the dialog. |
| `https://developer.android.com/reference/kotlin/androidx/preference/ListPreference` | A `https://developer.android.com/reference/kotlin/androidx/preference/Preference` that displays a list of entries as a dialog. |
| `https://developer.android.com/reference/kotlin/androidx/preference/MultiSelectListPreference` | A `https://developer.android.com/reference/kotlin/androidx/preference/Preference` that displays a list of entries as a dialog. |
| `https://developer.android.com/reference/kotlin/androidx/preference/PreferenceCategory` | A container that is used to group similar `https://developer.android.com/reference/kotlin/androidx/preference/Preference`s. |
| `https://developer.android.com/reference/kotlin/androidx/preference/PreferenceScreen` | A top-level container that represents a settings screen. |
| `https://developer.android.com/reference/kotlin/androidx/preference/SwitchPreferenceCompat` | A `https://developer.android.com/reference/kotlin/androidx/preference/Preference` that provides a two-state toggleable option. |
| `https://developer.android.com/reference/kotlin/androidx/preference/SwitchPreference` | A `https://developer.android.com/reference/kotlin/androidx/preference/Preference` that provides a two-state toggleable option. |

*** ** * ** ***

The basic building block that represents an individual setting displayed to a user in the preference hierarchy. This class provides the data that will be displayed to the user and has a reference to the `https://developer.android.com/reference/android/content/SharedPreferences.html` or `https://developer.android.com/reference/kotlin/androidx/preference/PreferenceDataStore` instance that persists the preference's values.

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

This class contains a `key` that that represents the key that is used to persist the value to the device. It is up to the subclass to decide how to store the value.

name android:icon

name android:key

name android:title

name android:summary

name android:order

name android:fragment

name android:layout

name android:widgetLayout

name android:enabled

name android:selectable

name android:dependency

name android:persistent

name android:defaultValue

name android:shouldDisableView

name android:singleLineTitle

name android:iconSpaceReserved

## Summary

| ### Nested types |
|---|
| `class https://developer.android.com/reference/kotlin/androidx/preference/Preference.BaseSavedState : https://developer.android.com/reference/android/view/AbsSavedState.html` A base class for managing the instance state of a `https://developer.android.com/reference/kotlin/androidx/preference/Preference`. |
| `interface https://developer.android.com/reference/kotlin/androidx/preference/Preference.OnPreferenceChangeListener` Interface definition for a callback to be invoked when the value of this `https://developer.android.com/reference/kotlin/androidx/preference/Preference` has been changed by the user and is about to be set and/or persisted. |
| `interface https://developer.android.com/reference/kotlin/androidx/preference/Preference.OnPreferenceClickListener` Interface definition for a callback to be invoked when a `https://developer.android.com/reference/kotlin/androidx/preference/Preference` is clicked. |
| `interface https://developer.android.com/reference/kotlin/androidx/preference/Preference.SummaryProvider<T : https://developer.android.com/reference/kotlin/androidx/preference/Preference?>` Interface definition for a callback to be invoked when the summary of this `https://developer.android.com/reference/kotlin/androidx/preference/Preference` is requested (typically when this preference is added to the hierarchy or its value is updated). |

| ### Constants |
|---|---|
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/preference/Preference#DEFAULT_ORDER() = 2147483647` Specify for `https://developer.android.com/reference/kotlin/androidx/preference/Preference#setOrder(int)` if a specific order is not required. |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/kotlin/androidx/preference/Preference#Preference(android.content.Context)(context: https://developer.android.com/reference/android/content/Context.html)` Constructor to create a preference. |
| `https://developer.android.com/reference/kotlin/androidx/preference/Preference#Preference(android.content.Context,android.util.AttributeSet)(context: https://developer.android.com/reference/android/content/Context.html, attrs: https://developer.android.com/reference/android/util/AttributeSet.html?)` Constructor that is called when inflating a preference from XML. |
| `https://developer.android.com/reference/kotlin/androidx/preference/Preference#Preference(android.content.Context,android.util.AttributeSet,int)(context: https://developer.android.com/reference/android/content/Context.html, attrs: https://developer.android.com/reference/android/util/AttributeSet.html?, defStyleAttr: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Perform inflation from XML and apply a class-specific base style. |
| `https://developer.android.com/reference/kotlin/androidx/preference/Preference#Preference(android.content.Context,android.util.AttributeSet,int,int)( context: https://developer.android.com/reference/android/content/Context.html, attrs: https://developer.android.com/reference/android/util/AttributeSet.html?, defStyleAttr: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, defStyleRes: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html )` Perform inflation from XML and apply a class-specific base style. |

| ### Public functions |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/preference/Preference#callChangeListener(java.lang.Object)(newValue: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html!)` Call this method after the user changes the preference, but before the internal state is set. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/preference/Preference#compareTo(androidx.preference.Preference)(another: https://developer.android.com/reference/kotlin/androidx/preference/Preference)` Compares preference objects based on order (if set), otherwise alphabetically on the titles. |
| `https://developer.android.com/reference/android/content/Context.html` | `https://developer.android.com/reference/kotlin/androidx/preference/Preference#getContext()()` Returns the `https://developer.android.com/reference/android/content/Context.html` of this preference. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?` | `https://developer.android.com/reference/kotlin/androidx/preference/Preference#getDependency()()` Returns the key of the dependency on this preference. |
| `https://developer.android.com/reference/android/os/Bundle.html` | `https://developer.android.com/reference/kotlin/androidx/preference/Preference#getExtras()()` Return the extras Bundle object associated with this preference, creating a new Bundle if there currently isn't one. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?` | `https://developer.android.com/reference/kotlin/androidx/preference/Preference#getFragment()()` Return the fragment class name associated with this preference. |
| `https://developer.android.com/reference/android/graphics/drawable/Drawable.html?` | `https://developer.android.com/reference/kotlin/androidx/preference/Preference#getIcon()()` Returns the icon of this preference. |
| `https://developer.android.com/reference/android/content/Intent.html?` | `https://developer.android.com/reference/kotlin/androidx/preference/Preference#getIntent()()` Return the `https://developer.android.com/reference/android/content/Intent.html` associated with this preference. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!` | `https://developer.android.com/reference/kotlin/androidx/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.html` or `https://developer.android.com/reference/kotlin/androidx/preference/PreferenceDataStore`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/preference/Preference#getLayoutResource()()` Gets the layout resource that will be shown as the `https://developer.android.com/reference/android/view/View.html` for this preference. |
| `https://developer.android.com/reference/kotlin/androidx/preference/Preference.OnPreferenceChangeListener?` | `https://developer.android.com/reference/kotlin/androidx/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/kotlin/androidx/preference/Preference.OnPreferenceClickListener?` | `https://developer.android.com/reference/kotlin/androidx/preference/Preference#getOnPreferenceClickListener()()` Returns the callback to be invoked when this preference is clicked. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/preference/Preference#getOrder()()` Gets the order of this preference with respect to other preference objects on the same level. |
| `https://developer.android.com/reference/kotlin/androidx/preference/PreferenceGroup?` | `https://developer.android.com/reference/kotlin/androidx/preference/Preference#getParent()()` Returns the `https://developer.android.com/reference/kotlin/androidx/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://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-set/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-set/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!>!` | `https://developer.android.com/reference/kotlin/androidx/preference/Preference#getPersistedStringSet(java.util.Set<java.lang.String>)(defaultReturnValue: (https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-set/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-set/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!>!)` Attempts to get a persisted set of Strings if this preference is persistent. |
| `https://developer.android.com/reference/kotlin/androidx/preference/PreferenceDataStore?` | `https://developer.android.com/reference/kotlin/androidx/preference/Preference#getPreferenceDataStore()()` Returns `https://developer.android.com/reference/kotlin/androidx/preference/PreferenceDataStore` used by this preference. |
| `https://developer.android.com/reference/kotlin/androidx/preference/PreferenceManager!` | `https://developer.android.com/reference/kotlin/androidx/preference/Preference#getPreferenceManager()()` Gets the `https://developer.android.com/reference/kotlin/androidx/preference/PreferenceManager` that manages this preference object's tree. |
| `https://developer.android.com/reference/android/content/SharedPreferences.html?` | `https://developer.android.com/reference/kotlin/androidx/preference/Preference#getSharedPreferences()()` Returns the `https://developer.android.com/reference/android/content/SharedPreferences.html` where this preference can read its value(s). |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/preference/Preference#getShouldDisableView()()` Checks whether this preference should disable its view when it's action is disabled. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-char-sequence/index.html?` | `https://developer.android.com/reference/kotlin/androidx/preference/Preference#getSummary()()` Returns the summary of this preference. |
| `https://developer.android.com/reference/kotlin/androidx/preference/Preference.SummaryProvider?` | `https://developer.android.com/reference/kotlin/androidx/preference/Preference#getSummaryProvider()()` Returns the `https://developer.android.com/reference/kotlin/androidx/preference/Preference.SummaryProvider` used to configure the summary of this preference. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-char-sequence/index.html?` | `https://developer.android.com/reference/kotlin/androidx/preference/Preference#getTitle()()` Returns the title of this preference. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/preference/Preference#getWidgetLayoutResource()()` Gets the layout resource for the controllable widget portion of this preference. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/preference/Preference#hasKey()()` Checks whether this preference has a valid key. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/preference/Preference#isCopyingEnabled()()` Returns whether the summary of this preference can be copied to the clipboard by long pressing on the preference. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/preference/Preference#isEnabled()()` Checks whether this preference should be enabled in the list. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/preference/Preference#isIconSpaceReserved()()` Returns whether the space of this preference icon view is reserved. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/preference/Preference#isPersistent()()` Checks whether this preference is persistent. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/preference/Preference#isSelectable()()` Checks whether this preference should be selectable in the list. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/preference/Preference#isShown()()` Checks whether this preference is shown to the user in the hierarchy. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/preference/Preference#isSingleLineTitle()()` Gets whether the title of this preference is constrained to a single line. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/preference/Preference#isVisible()()` Checks whether this preference should be visible to the user. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/preference/Preference#notifyDependencyChange(boolean)(disableDependents: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)` Notifies any listening dependents of a change that affects the dependency. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/preference/Preference#onAttached()()` Called when the preference hierarchy has been attached to the list of preferences. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/preference/Preference#onBindViewHolder(androidx.preference.PreferenceViewHolder)(holder: https://developer.android.com/reference/kotlin/androidx/preference/PreferenceViewHolder)` Binds the created View to the data for this preference. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/preference/Preference#onDependencyChanged(androidx.preference.Preference,boolean)(dependency: https://developer.android.com/reference/kotlin/androidx/preference/Preference, disableDependent: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)` Called when the dependency changes. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/preference/Preference#onDetached()()` Called when the preference hierarchy has been detached from the list of preferences. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `@https://developer.android.com/reference/kotlin/androidx/annotation/CallSuper [onInitializeAccessibilityNodeInfo](https://developer.android.com/reference/kotlin/androidx/preference/Preference#onInitializeAccessibilityNodeInfo(androidx.core.view.accessibility.AccessibilityNodeInfoCompat))(info: https://developer.android.com/reference/kotlin/androidx/core/view/accessibility/AccessibilityNodeInfoCompat!)` **This function is deprecated.** Preferences aren't views. <br /> |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/preference/Preference#onParentChanged(androidx.preference.Preference,boolean)(parent: https://developer.android.com/reference/kotlin/androidx/preference/Preference, disableChild: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)` Called when the implicit parent dependency changes. |
| `https://developer.android.com/reference/android/os/Bundle.html?` | `https://developer.android.com/reference/kotlin/androidx/preference/Preference#peekExtras()()` Return the extras Bundle object associated with this preference, returning `null` if there is not currently one. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/preference/Preference#persistStringSet(java.util.Set<java.lang.String>)(values: (https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-set/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-set/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!>!)` Attempts to persist a set of Strings if this preference is persistent. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/preference/Preference#restoreHierarchyState(android.os.Bundle)(container: https://developer.android.com/reference/android/os/Bundle.html)` Restore this preference hierarchy's previously saved state from the given container. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/preference/Preference#saveHierarchyState(android.os.Bundle)(container: https://developer.android.com/reference/android/os/Bundle.html)` Store this preference hierarchy's frozen state into the given container. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/preference/Preference#setCopyingEnabled(boolean)(enabled: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)` Sets whether the summary of this preference can be copied to the clipboard by long pressing on the preference. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/preference/Preference#setDefaultValue(java.lang.Object)(defaultValue: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html!)` 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. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/preference/Preference#setDependency(java.lang.String)(dependencyKey: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?)` Sets the key of a preference that this preference will depend on. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/preference/Preference#setEnabled(boolean)(enabled: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)` Sets whether this preference is enabled. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/preference/Preference#setFragment(java.lang.String)(fragment: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?)` Sets the class name of a fragment to be shown when this preference is clicked. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/preference/Preference#setIcon(android.graphics.drawable.Drawable)(icon: https://developer.android.com/reference/android/graphics/drawable/Drawable.html?)` Sets the icon for this preference with a Drawable. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/preference/Preference#setIcon(int)(iconResId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Sets the icon for this preference with a resource ID. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/preference/Preference#setIconSpaceReserved(boolean)(iconSpaceReserved: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)` Sets whether to reserve the space of this preference icon view when no icon is provided. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/preference/Preference#setIntent(android.content.Intent)(intent: https://developer.android.com/reference/android/content/Intent.html?)` Sets an `https://developer.android.com/reference/android/content/Intent.html` to be used for `https://developer.android.com/reference/android/content/Context.html#startActivity(android.content.Intent)` when this preference is clicked. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/preference/Preference#setKey(java.lang.String)(key: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!)` Sets the key for this preference, which is used as a key to the `https://developer.android.com/reference/android/content/SharedPreferences.html` or `https://developer.android.com/reference/kotlin/androidx/preference/PreferenceDataStore`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/preference/Preference#setLayoutResource(int)(layoutResId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Sets the layout resource that is inflated as the `https://developer.android.com/reference/android/view/View.html` to be shown for this preference. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/preference/Preference#setOnPreferenceChangeListener(androidx.preference.Preference.OnPreferenceChangeListener)( onPreferenceChangeListener: https://developer.android.com/reference/kotlin/androidx/preference/Preference.OnPreferenceChangeListener? )` Sets the callback to be invoked when this preference is changed by the user (but before the internal state has been updated). |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/preference/Preference#setOnPreferenceClickListener(androidx.preference.Preference.OnPreferenceClickListener)( onPreferenceClickListener: https://developer.android.com/reference/kotlin/androidx/preference/Preference.OnPreferenceClickListener? )` Sets the callback to be invoked when this preference is clicked. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/preference/Preference#setOrder(int)(order: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Sets the order of this preference with respect to other preference objects on the same level. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/preference/Preference#setPersistent(boolean)(persistent: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)` Sets whether this preference is persistent. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/preference/Preference#setPreferenceDataStore(androidx.preference.PreferenceDataStore)(dataStore: https://developer.android.com/reference/kotlin/androidx/preference/PreferenceDataStore?)` Sets a `https://developer.android.com/reference/kotlin/androidx/preference/PreferenceDataStore` to be used by this preference instead of using `https://developer.android.com/reference/android/content/SharedPreferences.html`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/preference/Preference#setSelectable(boolean)(selectable: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)` Sets whether this preference is selectable. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/preference/Preference#setShouldDisableView(boolean)(shouldDisableView: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)` Sets whether this preference should disable its view when it gets disabled. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/preference/Preference#setSingleLineTitle(boolean)(singleLineTitle: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)` Sets whether to constrain the title of this preference to a single line instead of letting it wrap onto multiple lines. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/preference/Preference#setSummary(java.lang.CharSequence)(summary: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-char-sequence/index.html?)` Sets the summary for this preference with a CharSequence. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/preference/Preference#setSummary(int)(summaryResId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Sets the summary for this preference with a resource ID. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/preference/Preference#setSummaryProvider(androidx.preference.Preference.SummaryProvider)(summaryProvider: https://developer.android.com/reference/kotlin/androidx/preference/Preference.SummaryProvider?)` Set a `https://developer.android.com/reference/kotlin/androidx/preference/Preference.SummaryProvider` that will be invoked whenever the summary of this preference is requested. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/preference/Preference#setTitle(java.lang.CharSequence)(title: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-char-sequence/index.html?)` Sets the title for this preference with a CharSequence. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/preference/Preference#setTitle(int)(titleResId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Sets the title for this preference with a resource ID. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/preference/Preference#setViewId(int)(viewId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Set the ID that will be assigned to the overall View representing this preference, once bound. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/preference/Preference#setVisible(boolean)(visible: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)` Sets whether this preference should be visible to the user. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/preference/Preference#setWidgetLayoutResource(int)(widgetLayoutResId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Sets the layout for the controllable widget portion of this preference. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/preference/Preference#shouldDisableDependents()()` Checks whether this preference's dependents should currently be disabled. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | `https://developer.android.com/reference/kotlin/androidx/preference/Preference#toString()()` |

| ### Protected functions |
|---|---|
| `T?` | `<T : https://developer.android.com/reference/kotlin/androidx/preference/Preference?> https://developer.android.com/reference/kotlin/androidx/preference/Preference#findPreferenceInHierarchy(java.lang.String)(key: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)` Finds a preference in the entire hierarchy (above or below this preference) with the given key. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/preference/Preference#getPersistedBoolean(boolean)(defaultReturnValue: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)` Attempts to get a persisted `https://developer.android.com/reference/java/lang/Boolean.html` if this preference is persistent. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/preference/Preference#getPersistedFloat(float)(defaultReturnValue: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)` Attempts to get a persisted `https://developer.android.com/reference/java/lang/Float.html` if this preference is persistent. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/preference/Preference#getPersistedInt(int)(defaultReturnValue: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Attempts to get a persisted `https://developer.android.com/reference/java/lang/Integer.html` if this preference is persistent. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | `https://developer.android.com/reference/kotlin/androidx/preference/Preference#getPersistedLong(long)(defaultReturnValue: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)` Attempts to get a persisted `https://developer.android.com/reference/java/lang/Long.html` if this preference is persistent. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!` | `https://developer.android.com/reference/kotlin/androidx/preference/Preference#getPersistedString(java.lang.String)(defaultReturnValue: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!)` Attempts to get a persisted set of Strings if this preference is persistent. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/preference/Preference#notifyChanged()()` Should be called when the data of this `https://developer.android.com/reference/kotlin/androidx/preference/Preference` has changed. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/preference/Preference#notifyHierarchyChanged()()` Should be called when a preference has been added/removed from this group, or the ordering should be re-evaluated. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/preference/Preference#onAttachedToHierarchy(androidx.preference.PreferenceManager)(preferenceManager: https://developer.android.com/reference/kotlin/androidx/preference/PreferenceManager)` Called when this preference has been attached to a preference hierarchy. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/preference/Preference#onClick()()` Processes a click on the preference. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?` | `https://developer.android.com/reference/kotlin/androidx/preference/Preference#onGetDefaultValue(android.content.res.TypedArray,int)(a: https://developer.android.com/reference/android/content/res/TypedArray.html, index: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Called when a preference is being inflated and the default value attribute needs to be read. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/preference/Preference#onPrepareForRemoval()()` Called when this preference is being removed from the hierarchy. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/preference/Preference#onRestoreInstanceState(android.os.Parcelable)(state: https://developer.android.com/reference/android/os/Parcelable.html?)` Hook allowing a preference to re-apply a representation of its internal state that had previously been generated by `https://developer.android.com/reference/kotlin/androidx/preference/Preference#onSaveInstanceState()`. |
| `https://developer.android.com/reference/android/os/Parcelable.html?` | `https://developer.android.com/reference/kotlin/androidx/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. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/preference/Preference#onSetInitialValue(java.lang.Object)(defaultValue: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?)` Implement this to set the initial value of the preference. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `[onSetInitialValue](https://developer.android.com/reference/kotlin/androidx/preference/Preference#onSetInitialValue(boolean,java.lang.Object))(restorePersistedValue: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html, defaultValue: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html!)` **This function is deprecated.** Use `https://developer.android.com/reference/kotlin/androidx/preference/Preference#onSetInitialValue(java.lang.Object)` instead. <br /> |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/preference/Preference#persistBoolean(boolean)(value: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)` Attempts to persist a `https://developer.android.com/reference/java/lang/Boolean.html` if this preference is persistent. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/preference/Preference#persistFloat(float)(value: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)` Attempts to persist a `https://developer.android.com/reference/java/lang/Float.html` if this preference is persistent. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/preference/Preference#persistInt(int)(value: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Attempts to persist an `https://developer.android.com/reference/java/lang/Integer.html` if this preference is persistent. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/preference/Preference#persistLong(long)(value: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)` Attempts to persist a `https://developer.android.com/reference/java/lang/Long.html` if this preference is persistent. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/preference/Preference#persistString(java.lang.String)(value: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!)` Attempts to persist a `https://developer.android.com/reference/java/lang/String.html` if this preference is persistent. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/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.html` or into `https://developer.android.com/reference/kotlin/androidx/preference/PreferenceDataStore` if assigned. |

## Constants

### DEFAULT_ORDER

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

```
const val DEFAULT_ORDER = 2147483647: Int
```

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

## Public constructors

### Preference

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

```
Preference(context: Context)
```

Constructor to create a preference.

| Parameters |
|---|---|
| `context: https://developer.android.com/reference/android/content/Context.html` | The Context this is associated with, through which it can access the current theme, resources, `https://developer.android.com/reference/android/content/SharedPreferences.html`, etc. |

### Preference

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

```
Preference(context: Context, attrs: AttributeSet?)
```

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.

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

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/preference/Preference#Preference(android.content.Context,android.util.AttributeSet,int)` |   |

### Preference

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

```
Preference(context: Context, attrs: AttributeSet?, defStyleAttr: Int)
```

Perform inflation from XML and apply a class-specific base style. This constructor allows subclasses to use their own base style when they are inflating. For example, a `https://developer.android.com/reference/kotlin/androidx/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/kotlin/androidx/preference/CheckBoxPreference` class's attributes.

| Parameters |
|---|---|
| `context: https://developer.android.com/reference/android/content/Context.html` | The Context this is associated with, through which it can access the current theme, resources, `https://developer.android.com/reference/android/content/SharedPreferences.html`, etc. |
| `attrs: https://developer.android.com/reference/android/util/AttributeSet.html?` | The attributes of the XML tag that is inflating the preference |
| `defStyleAttr: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | 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. |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/preference/Preference#Preference(android.content.Context,android.util.AttributeSet)` |   |

### Preference

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

```
Preference(
    context: Context,
    attrs: AttributeSet?,
    defStyleAttr: Int,
    defStyleRes: Int
)
```

Perform inflation from XML and apply a class-specific base style. This constructor allows subclasses to use their own base style when they are inflating. For example, a `https://developer.android.com/reference/kotlin/androidx/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/kotlin/androidx/preference/CheckBoxPreference` class's attributes.

| Parameters |
|---|---|
| `context: https://developer.android.com/reference/android/content/Context.html` | The `https://developer.android.com/reference/android/content/Context.html` this is associated with, through which it can access the current theme, resources, `https://developer.android.com/reference/android/content/SharedPreferences.html`, etc. |
| `attrs: https://developer.android.com/reference/android/util/AttributeSet.html?` | The attributes of the XML tag that is inflating the preference |
| `defStyleAttr: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | 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. |
| `defStyleRes: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | 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. |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/preference/Preference#Preference(android.content.Context,android.util.AttributeSet)` |   |

## Public functions

### callChangeListener

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

```
fun callChangeListener(newValue: Any!): Boolean
```

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.

| Parameters |
|---|---|
| `newValue: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html!` | The new value of this preference |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `true` if the user value should be set as the preference value (and persisted) |

### compareTo

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

```
fun compareTo(another: Preference): Int
```

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

| Parameters |
|---|---|
| `another: https://developer.android.com/reference/kotlin/androidx/preference/Preference` | The preference to compare to this one |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | 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>. |

### getContext

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

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

Returns the `https://developer.android.com/reference/android/content/Context.html` 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/kotlin/androidx/preference/PreferenceFragmentCompat`). This Context will be used to save the preference values.

| Returns |
|---|---|
| `https://developer.android.com/reference/android/content/Context.html` | The Context of this preference |

### getDependency

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

```
fun getDependency(): String?
```

Returns the key of the dependency on this preference.

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?` | The key of the dependency |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/preference/Preference#setDependency(java.lang.String)` |   |

### getExtras

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

```
fun getExtras(): Bundle
```

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.

### getFragment

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

```
fun getFragment(): String?
```

Return the fragment class name associated with this preference.

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?` | The fragment class name last set via `https://developer.android.com/reference/kotlin/androidx/preference/Preference#setFragment(java.lang.String)` or XML |

### getIcon

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

```
fun getIcon(): Drawable?
```

Returns the icon of this preference.

| Returns |
|---|---|
| `https://developer.android.com/reference/android/graphics/drawable/Drawable.html?` | The icon |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/preference/Preference#setIcon(android.graphics.drawable.Drawable)` |   |

### getIntent

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

```
fun getIntent(): Intent?
```

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

| Returns |
|---|---|
| `https://developer.android.com/reference/android/content/Intent.html?` | The `https://developer.android.com/reference/android/content/Intent.html` last set via `https://developer.android.com/reference/kotlin/androidx/preference/Preference#setIntent(android.content.Intent)` or XML |

### getKey

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

```
fun getKey(): String!
```

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

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!` | The key |

### getLayoutResource

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

```
fun getLayoutResource(): Int
```

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

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The layout resource ID |

### getOnPreferenceChangeListener

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

```
fun getOnPreferenceChangeListener(): Preference.OnPreferenceChangeListener?
```

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

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/preference/Preference.OnPreferenceChangeListener?` | The callback to be invoked |

### getOnPreferenceClickListener

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

```
fun getOnPreferenceClickListener(): Preference.OnPreferenceClickListener?
```

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

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/preference/Preference.OnPreferenceClickListener?` | The callback to be invoked |

### getOrder

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

```
fun getOrder(): Int
```

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

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The order of this preference |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/preference/Preference#setOrder(int)` |   |

### getParent

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

```
fun getParent(): PreferenceGroup?
```

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

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/preference/PreferenceGroup?` | The parent PreferenceGroup or `null` if not attached to any |

### getPersistedStringSet

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

```
fun getPersistedStringSet(defaultReturnValue: (Mutable)Set<String!>!): (Mutable)Set<String!>!
```

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

| Parameters |
|---|---|
| `defaultReturnValue: (https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-set/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-set/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!>!` | The default value to return if either this preference is not persistent or this preference is not present. |

| Returns |
|---|---|
| `(https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-set/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-set/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!>!` | The value from the storage or the default return value |

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

### getPreferenceDataStore

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

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

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

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

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/preference/PreferenceDataStore?` | The `https://developer.android.com/reference/kotlin/androidx/preference/PreferenceDataStore` used by this preference or `null` if none |

### getPreferenceManager

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

```
fun getPreferenceManager(): PreferenceManager!
```

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

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/preference/PreferenceManager!` | The `https://developer.android.com/reference/kotlin/androidx/preference/PreferenceManager` |

### getSharedPreferences

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

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

Returns the `https://developer.android.com/reference/android/content/SharedPreferences.html` 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/kotlin/androidx/preference/Preference#getPersistedBoolean(boolean)`, `https://developer.android.com/reference/kotlin/androidx/preference/Preference#getPersistedFloat(float)`, `https://developer.android.com/reference/kotlin/androidx/preference/Preference#getPersistedInt(int)`, `https://developer.android.com/reference/kotlin/androidx/preference/Preference#getPersistedLong(long)`, `https://developer.android.com/reference/kotlin/androidx/preference/Preference#getPersistedString(java.lang.String)`.

| Returns |
|---|---|
| `https://developer.android.com/reference/android/content/SharedPreferences.html?` | The `https://developer.android.com/reference/android/content/SharedPreferences.html` where this preference reads its value(s). If this preference is not attached to a preference hierarchy or if a `https://developer.android.com/reference/kotlin/androidx/preference/PreferenceDataStore` has been set, this method returns `null`. |

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

### getShouldDisableView

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

```
fun getShouldDisableView(): Boolean
```

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

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `true` if it should disable the view |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/preference/Preference#setShouldDisableView(boolean)` |   |

### getSummary

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

```
fun getSummary(): CharSequence?
```

Returns the summary of this preference. If a `https://developer.android.com/reference/kotlin/androidx/preference/Preference.SummaryProvider` has been set for this preference, it will be used to provide the summary returned by this method.

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-char-sequence/index.html?` | The summary |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/preference/Preference#setSummary(java.lang.CharSequence)` |   |
| `https://developer.android.com/reference/kotlin/androidx/preference/Preference#setSummaryProvider(androidx.preference.Preference.SummaryProvider)` |   |

### getSummaryProvider

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

```
fun getSummaryProvider(): Preference.SummaryProvider?
```

Returns the `https://developer.android.com/reference/kotlin/androidx/preference/Preference.SummaryProvider` used to configure the summary of this preference.

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/preference/Preference.SummaryProvider?` | The `https://developer.android.com/reference/kotlin/androidx/preference/Preference.SummaryProvider` used to configure the summary of this preference, or `null` if there is no SummaryProvider set |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/preference/Preference.SummaryProvider` |   |

### getTitle

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

```
fun getTitle(): CharSequence?
```

Returns the title of this preference.

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-char-sequence/index.html?` | The title |

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

### getWidgetLayoutResource

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

```
fun getWidgetLayoutResource(): Int
```

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

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The layout resource ID |

### hasKey

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

```
fun hasKey(): Boolean
```

Checks whether this preference has a valid key.

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `true` if the key exists and is not a blank string, false otherwise |

### isCopyingEnabled

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

```
fun isCopyingEnabled(): Boolean
```

Returns whether the summary of this preference can be copied to the clipboard by long pressing on the preference.

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `true` if copying is enabled, false otherwise |

### isEnabled

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

```
fun isEnabled(): Boolean
```

Checks whether this preference should be enabled in the list.

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `true` if this preference is enabled, false otherwise |

### isIconSpaceReserved

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

```
fun isIconSpaceReserved(): Boolean
```

Returns whether the space of this preference icon view is reserved.

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `true` if the space of this preference icon view is reserved `https://developer.android.com/reference/android/R.attr.html#iconSpaceReserved` |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/preference/Preference#setIconSpaceReserved(boolean)` |   |

### isPersistent

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

```
fun isPersistent(): Boolean
```

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.html` storage by default or into `https://developer.android.com/reference/kotlin/androidx/preference/PreferenceDataStore` if assigned.

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `true` if persistent |

### isSelectable

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

```
fun isSelectable(): Boolean
```

Checks whether this preference should be selectable in the list.

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `true` if it is selectable, false otherwise |

### isShown

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

```
fun isShown(): Boolean
```

Checks whether this preference is shown to the user in the hierarchy. For a preference to be shown in the hierarchy, it and all of its ancestors must be visible and attached to the root `https://developer.android.com/reference/kotlin/androidx/preference/PreferenceScreen`.

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `true` if this preference is shown to the user in the hierarchy |

### isSingleLineTitle

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

```
fun isSingleLineTitle(): Boolean
```

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

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `true` if the title of this preference is constrained to a single line `https://developer.android.com/reference/android/R.attr.html#singleLineTitle` |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/preference/Preference#setSingleLineTitle(boolean)` |   |

### isVisible

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

```
fun isVisible(): Boolean
```

Checks whether this preference should be visible to the user. If this preference is visible, but one or more of its ancestors are not visible, then this preference will not be shown until its ancestors are all visible.

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `true` if this preference should be displayed |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/preference/Preference#setVisible(boolean)` |   |
| `https://developer.android.com/reference/kotlin/androidx/preference/Preference#isShown()` |   |

### notifyDependencyChange

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

```
fun notifyDependencyChange(disableDependents: Boolean): Unit
```

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

| Parameters |
|---|---|
| `disableDependents: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | Whether this preference should disable its dependents. |

### onAttached

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

```
fun onAttached(): Unit
```

Called when the preference hierarchy has been attached to the list of preferences. This can also be called when this preference has been attached to a group that was already attached to the list of preferences.

### onBindViewHolder

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

```
fun onBindViewHolder(holder: PreferenceViewHolder): Unit
```

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.

| Parameters |
|---|---|
| `holder: https://developer.android.com/reference/kotlin/androidx/preference/PreferenceViewHolder` | The ViewHolder that provides references to the views to fill in. These views will be recycled, so you should not hold a reference to them after this method returns. |

### onDependencyChanged

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

```
fun onDependencyChanged(dependency: Preference, disableDependent: Boolean): Unit
```

Called when the dependency changes.

| Parameters |
|---|---|
| `dependency: https://developer.android.com/reference/kotlin/androidx/preference/Preference` | The preference that this preference depends on |
| `disableDependent: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | Set true to disable this preference |

### onDetached

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

```
fun onDetached(): Unit
```

Called when the preference hierarchy has been detached from the list of preferences. This can also be called when this preference has been removed from a group that was attached to the list of preferences.

### onInitializeAccessibilityNodeInfo

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

```
@CallSuper
fun [onInitializeAccessibilityNodeInfo](https://developer.android.com/reference/kotlin/androidx/preference/Preference#onInitializeAccessibilityNodeInfo(androidx.core.view.accessibility.AccessibilityNodeInfoCompat))(info: AccessibilityNodeInfoCompat!): Unit
```

> [!CAUTION]
> **This function is deprecated.**   
>
> Preferences aren't views. They should not need any accessibility changes, unless the view hierarchy is customized. In this situation, please add Accessibility information in `https://developer.android.com/reference/kotlin/androidx/preference/Preference#onBindViewHolder(androidx.preference.PreferenceViewHolder)`.

Initializes an `https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeInfo.html` with information about the View for this preference.

### onParentChanged

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

```
fun onParentChanged(parent: Preference, disableChild: Boolean): Unit
```

Called when the implicit parent dependency changes.

| Parameters |
|---|---|
| `parent: https://developer.android.com/reference/kotlin/androidx/preference/Preference` | The preference that this preference depends on |
| `disableChild: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | Set true to disable this preference |

### peekExtras

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

```
fun peekExtras(): Bundle?
```

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

### persistStringSet

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

```
fun persistStringSet(values: (Mutable)Set<String!>!): Boolean
```

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

The returned value doesn't reflect whether the given value was persisted, since we may not necessarily commit if there will be a batch commit later.

| Parameters |
|---|---|
| `values: (https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-set/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-set/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!>!` | The values to persist |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `true` if the preference is persistent, `false` otherwise |

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

### restoreHierarchyState

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

```
fun restoreHierarchyState(container: Bundle): Unit
```

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

| Parameters |
|---|---|
| `container: https://developer.android.com/reference/android/os/Bundle.html` | The Bundle that holds the previously saved state |

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

### saveHierarchyState

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

```
fun saveHierarchyState(container: Bundle): Unit
```

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

| Parameters |
|---|---|
| `container: https://developer.android.com/reference/android/os/Bundle.html` | The Bundle in which to save the instance of this preference |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/preference/Preference#restoreHierarchyState(android.os.Bundle)` |   |
| `https://developer.android.com/reference/kotlin/androidx/preference/Preference#onSaveInstanceState()` |   |

### setCopyingEnabled

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

```
fun setCopyingEnabled(enabled: Boolean): Unit
```

Sets whether the summary of this preference can be copied to the clipboard by long pressing on the preference.

| Parameters |
|---|---|
| `enabled: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | Set true to enable copying the summary of this preference |

### setDefaultValue

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

```
fun setDefaultValue(defaultValue: Any!): Unit
```

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.

| Parameters |
|---|---|
| `defaultValue: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html!` | The default value |

### setDependency

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

```
fun setDependency(dependencyKey: String?): Unit
```

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.

| Parameters |
|---|---|
| `dependencyKey: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?` | The key of the preference that this depends on |

### setEnabled

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

```
fun setEnabled(enabled: Boolean): Unit
```

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

| Parameters |
|---|---|
| `enabled: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | Set true to enable it |

### setFragment

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

```
fun setFragment(fragment: String?): Unit
```

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

| Parameters |
|---|---|
| `fragment: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?` | The class name of the fragment associated with this preference |

### setIcon

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

```
fun setIcon(icon: Drawable?): Unit
```

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.html#icon` within the View created by `https://developer.android.com/reference/kotlin/androidx/preference/Preference#onBindViewHolder(androidx.preference.PreferenceViewHolder)`.

| Parameters |
|---|---|
| `icon: https://developer.android.com/reference/android/graphics/drawable/Drawable.html?` | The optional icon for this preference |

### setIcon

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

```
fun setIcon(iconResId: Int): Unit
```

Sets the icon for this preference with a resource ID.

| Parameters |
|---|---|
| `iconResId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The icon as a resource ID |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/preference/Preference#setIcon(android.graphics.drawable.Drawable)` |   |

### setIconSpaceReserved

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

```
fun setIconSpaceReserved(iconSpaceReserved: Boolean): Unit
```

Sets whether to reserve the space of this preference icon view when no icon is provided. If set to true, the preference will be offset as if it would have the icon and thus aligned with other preferences having icons.

| Parameters |
|---|---|
| `iconSpaceReserved: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | Set `true` if the space for the icon view should be reserved `https://developer.android.com/reference/android/R.attr.html#iconSpaceReserved` |

### setIntent

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

```
fun setIntent(intent: Intent?): Unit
```

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

| Parameters |
|---|---|
| `intent: https://developer.android.com/reference/android/content/Intent.html?` | The intent associated with this preference |

### setKey

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

```
fun setKey(key: String!): Unit
```

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

| Parameters |
|---|---|
| `key: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!` | The key for the preference |

### setLayoutResource

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

```
fun setLayoutResource(layoutResId: Int): Unit
```

Sets the layout resource that is inflated as the `https://developer.android.com/reference/android/view/View.html` 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.html` with ID `https://developer.android.com/reference/android/R.id.html#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.html#title` and `https://developer.android.com/reference/android/R.id.html#summary`.

It is an error to change the layout after adding the preference to a `https://developer.android.com/reference/kotlin/androidx/preference/PreferenceGroup`.

| Parameters |
|---|---|
| `layoutResId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The layout resource ID to be inflated and returned as a `https://developer.android.com/reference/android/view/View.html` |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/preference/Preference#setWidgetLayoutResource(int)` |   |

### setOnPreferenceChangeListener

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

```
fun setOnPreferenceChangeListener(
    onPreferenceChangeListener: Preference.OnPreferenceChangeListener?
): Unit
```

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

| Parameters |
|---|---|
| `onPreferenceChangeListener: https://developer.android.com/reference/kotlin/androidx/preference/Preference.OnPreferenceChangeListener?` | The callback to be invoked |

### setOnPreferenceClickListener

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

```
fun setOnPreferenceClickListener(
    onPreferenceClickListener: Preference.OnPreferenceClickListener?
): Unit
```

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

| Parameters |
|---|---|
| `onPreferenceClickListener: https://developer.android.com/reference/kotlin/androidx/preference/Preference.OnPreferenceClickListener?` | The callback to be invoked |

### setOrder

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

```
fun setOrder(order: Int): Unit
```

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/kotlin/androidx/preference/PreferenceGroup#setOrderingAsAdded(boolean)` can be used to order preference objects based on the order they appear in the XML.

| Parameters |
|---|---|
| `order: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The order for this preference. A lower value will be shown first. Use `https://developer.android.com/reference/kotlin/androidx/preference/Preference#DEFAULT_ORDER()` to sort alphabetically or allow ordering from XML. |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/preference/PreferenceGroup#setOrderingAsAdded(boolean)` |   |
| `https://developer.android.com/reference/kotlin/androidx/preference/Preference#DEFAULT_ORDER()` |   |

### setPersistent

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

```
fun setPersistent(persistent: Boolean): Unit
```

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

| Parameters |
|---|---|
| `persistent: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | Set `true` if it should store its value(s) into the storage |

### setPreferenceDataStore

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

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

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

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/kotlin/androidx/preference/PreferenceManager` that owns this preference.

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

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

### setSelectable

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

```
fun setSelectable(selectable: Boolean): Unit
```

Sets whether this preference is selectable.

| Parameters |
|---|---|
| `selectable: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | Set true to make it selectable |

### setShouldDisableView

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

```
fun setShouldDisableView(shouldDisableView: Boolean): Unit
```

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

For example, set this and `https://developer.android.com/reference/kotlin/androidx/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.

| Parameters |
|---|---|
| `shouldDisableView: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | Set true if this preference should disable its view when the preference is disabled. |

### setSingleLineTitle

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

```
fun setSingleLineTitle(singleLineTitle: Boolean): Unit
```

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

| Parameters |
|---|---|
| `singleLineTitle: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | Set `true` if the title should be constrained to one line `https://developer.android.com/reference/android/R.attr.html#singleLineTitle` |

### setSummary

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

```
fun setSummary(summary: CharSequence?): Unit
```

Sets the summary for this preference with a CharSequence.

You can also use a `https://developer.android.com/reference/kotlin/androidx/preference/Preference.SummaryProvider` to dynamically configure the summary of this preference.

| Parameters |
|---|---|
| `summary: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-char-sequence/index.html?` | The summary for the preference |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalStateException.html` | If a `https://developer.android.com/reference/kotlin/androidx/preference/Preference.SummaryProvider` has already been set. |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/preference/Preference#setSummaryProvider(androidx.preference.Preference.SummaryProvider)` |   |

### setSummary

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

```
fun setSummary(summaryResId: Int): Unit
```

Sets the summary for this preference with a resource ID.

You can also use a `https://developer.android.com/reference/kotlin/androidx/preference/Preference.SummaryProvider` to dynamically configure the summary of this preference.

| Parameters |
|---|---|
| `summaryResId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The summary as a resource |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/preference/Preference#setSummary(java.lang.CharSequence)` |   |
| `https://developer.android.com/reference/kotlin/androidx/preference/Preference#setSummaryProvider(androidx.preference.Preference.SummaryProvider)` |   |

### setSummaryProvider

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

```
fun setSummaryProvider(summaryProvider: Preference.SummaryProvider?): Unit
```

Set a `https://developer.android.com/reference/kotlin/androidx/preference/Preference.SummaryProvider` that will be invoked whenever the summary of this preference is requested. Set `null` to remove the existing SummaryProvider.

| Parameters |
|---|---|
| `summaryProvider: https://developer.android.com/reference/kotlin/androidx/preference/Preference.SummaryProvider?` | The `https://developer.android.com/reference/kotlin/androidx/preference/Preference.SummaryProvider` that will be invoked whenever the summary of this preference is requested |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/preference/Preference.SummaryProvider` |   |

### setTitle

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

```
fun setTitle(title: CharSequence?): Unit
```

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.html#title` within the View bound by `https://developer.android.com/reference/kotlin/androidx/preference/Preference#onBindViewHolder(androidx.preference.PreferenceViewHolder)`.

| Parameters |
|---|---|
| `title: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-char-sequence/index.html?` | The title for this preference |

### setTitle

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

```
fun setTitle(titleResId: Int): Unit
```

Sets the title for this preference with a resource ID.

| Parameters |
|---|---|
| `titleResId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The title as a resource ID |

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

### setViewId

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

```
fun setViewId(viewId: Int): Unit
```

Set the ID that will be assigned to the overall View representing this preference, once bound.

| See also |
|---|---|
| `https://developer.android.com/reference/android/view/View.html#setId(int)` |   |

### setVisible

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

```
fun setVisible(visible: Boolean): Unit
```

Sets whether this preference should be visible to the user. If false, it is excluded from the adapter, but can still be retrieved using `https://developer.android.com/reference/kotlin/androidx/preference/PreferenceFragmentCompat#findPreference(java.lang.CharSequence)`.

To show this preference to the user, its ancestors must also all be visible. If you make a `https://developer.android.com/reference/kotlin/androidx/preference/PreferenceGroup` invisible, none of its children will be shown to the user until the group is visible.

| Parameters |
|---|---|
| `visible: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | Set false if this preference should be hidden from the user isPreferenceVisible |

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

### setWidgetLayoutResource

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

```
fun setWidgetLayoutResource(widgetLayoutResId: Int): Unit
```

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/kotlin/androidx/preference/CheckBoxPreference` would specify a custom layout (consisting of just the CheckBox) here, instead of creating its own main layout.

It is an error to change the layout after adding the preference to a `https://developer.android.com/reference/kotlin/androidx/preference/PreferenceGroup`.

| Parameters |
|---|---|
| `widgetLayoutResId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The layout resource ID to be inflated into the main layout |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/preference/Preference#setLayoutResource(int)` |   |

### shouldDisableDependents

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

```
fun shouldDisableDependents(): Boolean
```

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

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `true` if the dependents should be disabled, otherwise false |

### toString

```
fun toString(): String
```

## Protected functions

### findPreferenceInHierarchy

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

```
protected fun <T : Preference?> findPreferenceInHierarchy(key: String): T?
```

Finds a preference in the entire hierarchy (above or below this preference) with the given key. Returns `null` if no preference could be found with the given key.

This only works after this preference has been attached to a hierarchy.

| Parameters |
|---|---|
| `key: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | The key of the preference to retrieve |

| Returns |
|---|---|
| `T?` | The preference with the key, or `null` |

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

### getPersistedBoolean

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

```
protected fun getPersistedBoolean(defaultReturnValue: Boolean): Boolean
```

Attempts to get a persisted `https://developer.android.com/reference/java/lang/Boolean.html` if this preference is persistent.

| Parameters |
|---|---|
| `defaultReturnValue: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | The default value to return if either this preference is not persistent or this preference is not in the SharedPreferences. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | The value from the storage or the default return value |

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

### getPersistedFloat

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

```
protected fun getPersistedFloat(defaultReturnValue: Float): Float
```

Attempts to get a persisted `https://developer.android.com/reference/java/lang/Float.html` if this preference is persistent.

| Parameters |
|---|---|
| `defaultReturnValue: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | The default value to return if either this preference is not persistent or this preference is not saved. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | The value from the storage or the default return value |

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

### getPersistedInt

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

```
protected fun getPersistedInt(defaultReturnValue: Int): Int
```

Attempts to get a persisted `https://developer.android.com/reference/java/lang/Integer.html` if this preference is persistent.

| Parameters |
|---|---|
| `defaultReturnValue: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The default value to return if either this preference is not persistent or this preference is not in the SharedPreferences. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The value from the storage or the default return value |

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

### getPersistedLong

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

```
protected fun getPersistedLong(defaultReturnValue: Long): Long
```

Attempts to get a persisted `https://developer.android.com/reference/java/lang/Long.html` if this preference is persistent.

| Parameters |
|---|---|
| `defaultReturnValue: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | The default value to return if either this preference is not persistent or this preference is not in the SharedPreferences. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | The value from the storage or the default return value |

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

### getPersistedString

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

```
protected fun getPersistedString(defaultReturnValue: String!): String!
```

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

| Parameters |
|---|---|
| `defaultReturnValue: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!` | The default value to return if either the preference is not persistent or the preference is not in the shared preferences. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!` | The value from the storage or the default return value |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/preference/Preference#persistString(java.lang.String)` |   |

### notifyChanged

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

```
protected fun notifyChanged(): Unit
```

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

### notifyHierarchyChanged

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

```
protected fun notifyHierarchyChanged(): Unit
```

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

### onAttachedToHierarchy

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

```
protected fun onAttachedToHierarchy(preferenceManager: PreferenceManager): Unit
```

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

| Parameters |
|---|---|
| `preferenceManager: https://developer.android.com/reference/kotlin/androidx/preference/PreferenceManager` | The PreferenceManager of the hierarchy |

### onClick

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

```
protected fun onClick(): Unit
```

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

### onGetDefaultValue

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

```
protected fun onGetDefaultValue(a: TypedArray, index: Int): Any?
```

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.html#getString(int)`.

| Parameters |
|---|---|
| `a: https://developer.android.com/reference/android/content/res/TypedArray.html` | The set of attributes |
| `index: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The index of the default value attribute |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?` | The default value of this preference type |

### onPrepareForRemoval

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

```
protected fun onPrepareForRemoval(): Unit
```

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.

### onRestoreInstanceState

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

```
protected fun onRestoreInstanceState(state: Parcelable?): Unit
```

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

| Parameters |
|---|---|
| `state: https://developer.android.com/reference/android/os/Parcelable.html?` | The saved state that had previously been returned by `https://developer.android.com/reference/kotlin/androidx/preference/Preference#onSaveInstanceState()`. |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/preference/Preference#onSaveInstanceState()` |   |
| `https://developer.android.com/reference/kotlin/androidx/preference/Preference#restoreHierarchyState(android.os.Bundle)` |   |

### onSaveInstanceState

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

```
protected fun onSaveInstanceState(): Parcelable?
```

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.

| Returns |
|---|---|
| `https://developer.android.com/reference/android/os/Parcelable.html?` | 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`. |

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

### onSetInitialValue

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

```
protected fun onSetInitialValue(defaultValue: Any?): Unit
```

Implement this to set the initial value of the preference.

If you are persisting values to `https://developer.android.com/reference/android/content/SharedPreferences.html` or a `https://developer.android.com/reference/kotlin/androidx/preference/PreferenceDataStore` you should restore the saved value for the preference.

If you are not persisting values, or there is no value saved for the preference, you should set the value of the preference to <var translate="no">defaultValue</var>.

| Parameters |
|---|---|
| `defaultValue: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?` | The default value for the preference if set, otherwise `null`. |

### onSetInitialValue

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

```
protected fun [onSetInitialValue](https://developer.android.com/reference/kotlin/androidx/preference/Preference#onSetInitialValue(boolean,java.lang.Object))(restorePersistedValue: Boolean, defaultValue: Any!): Unit
```

> [!CAUTION]
> **This function is deprecated.**   
>
> Use `https://developer.android.com/reference/kotlin/androidx/preference/Preference#onSetInitialValue(java.lang.Object)` instead.

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.html`. 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/kotlin/androidx/preference/Preference#shouldPersist()` is true).

In case of using `https://developer.android.com/reference/kotlin/androidx/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.

| Parameters |
|---|---|
| `restorePersistedValue: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | True to restore the persisted value; false to use the given <var translate="no">defaultValue</var>. |
| `defaultValue: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html!` | The default value for this preference. Only use this if <var translate="no">restorePersistedValue</var> is false. |

### persistBoolean

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

```
protected fun persistBoolean(value: Boolean): Boolean
```

Attempts to persist a `https://developer.android.com/reference/java/lang/Boolean.html` if this preference is persistent.

The returned value doesn't reflect whether the given value was persisted, since we may not necessarily commit if there will be a batch commit later.

| Parameters |
|---|---|
| `value: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | The value to persist |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `true` if the preference is persistent, `false` otherwise |

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

### persistFloat

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

```
protected fun persistFloat(value: Float): Boolean
```

Attempts to persist a `https://developer.android.com/reference/java/lang/Float.html` if this preference is persistent.

The returned value doesn't reflect whether the given value was persisted, since we may not necessarily commit if there will be a batch commit later.

| Parameters |
|---|---|
| `value: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | The value to persist |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `true` if the preference is persistent, `false` otherwise |

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

### persistInt

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

```
protected fun persistInt(value: Int): Boolean
```

Attempts to persist an `https://developer.android.com/reference/java/lang/Integer.html` if this preference is persistent.

The returned value doesn't reflect whether the given value was persisted, since we may not necessarily commit if there will be a batch commit later.

| Parameters |
|---|---|
| `value: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The value to persist |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `true` if the preference is persistent, `false` otherwise |

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

### persistLong

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

```
protected fun persistLong(value: Long): Boolean
```

Attempts to persist a `https://developer.android.com/reference/java/lang/Long.html` if this preference is persistent.

The returned value doesn't reflect whether the given value was persisted, since we may not necessarily commit if there will be a batch commit later.

| Parameters |
|---|---|
| `value: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | The value to persist |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `true` if the preference is persistent, `false` otherwise |

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

### persistString

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

```
protected fun persistString(value: String!): Boolean
```

Attempts to persist a `https://developer.android.com/reference/java/lang/String.html` if this preference is persistent.

The returned value doesn't reflect whether the given value was persisted, since we may not necessarily commit if there will be a batch commit later.

| Parameters |
|---|---|
| `value: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!` | The value to persist |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `true` if the preference is persistent, `false` otherwise |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/preference/Preference#getPersistedString(java.lang.String)` |   |

### shouldPersist

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

```
protected fun shouldPersist(): Boolean
```

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.html` or into `https://developer.android.com/reference/kotlin/androidx/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.

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `true` if it should persist the value |