Stay organized with collections
Save and categorize content based on your preferences.
Preference.OnPreferenceChangeListener
public
static
interface
Preference.OnPreferenceChangeListener
android.preference.Preference.OnPreferenceChangeListener
|
This interface was deprecated
in API level 29.
Use the AndroidX
Preference Library for consistent behavior across all devices.
For more information on using the AndroidX Preference Library see
Settings.
Interface definition for a callback to be invoked when the value of this
Preference
has been changed by the user and is
about to be set and/or persisted. This gives the client a chance
to prevent setting and/or persisting the value.
Summary
Public methods
onPreferenceChange
public abstract boolean onPreferenceChange (Preference preference,
Object newValue)
Called when a Preference has been changed by the user. This is
called before the state of the Preference is about to be updated and
before the state is persisted.
Parameters |
preference |
Preference : The changed Preference. |
newValue |
Object : The new value of the Preference. |
Returns |
boolean |
True to update the state of the Preference with the new value. |
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-02-10 UTC."],[],[],null,["# Preference.OnPreferenceChangeListener\n\nAdded in [API level 1](/guide/topics/manifest/uses-sdk-element#ApiLevels) \nDeprecated in [API level\n29](/guide/topics/manifest/uses-sdk-element#ApiLevels) \n\nPreference.OnPreferenceChangeListener\n=====================================\n\n*** ** * ** ***\n\n[Kotlin](/reference/kotlin/android/preference/Preference.OnPreferenceChangeListener \"View this page in Kotlin\") \\|Java\n\n\n`\npublic\nstatic\n\n\ninterface\nPreference.OnPreferenceChangeListener\n`\n\n\n`\n\n\n`\n\n|----------------------------------------------------------|\n| android.preference.Preference.OnPreferenceChangeListener |\n\n\u003cbr /\u003e\n\n*** ** * ** ***\n\n\n**This interface was deprecated\nin API level 29.** \n\nUse the [AndroidX](/jetpack/androidx)\n[Preference Library](/reference/androidx/preference/package-summary) for consistent behavior across all devices.\nFor more information on using the AndroidX Preference Library see\n[Settings](/guide/topics/ui/settings).\n\nInterface definition for a callback to be invoked when the value of this\n[Preference](/reference/android/preference/Preference) has been changed by the user and is\nabout to be set and/or persisted. This gives the client a chance\nto prevent setting and/or persisting the value.\n\nSummary\n-------\n\n| ### Public methods ||\n|---------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| ` abstract boolean` | ` `[onPreferenceChange](/reference/android/preference/Preference.OnPreferenceChangeListener#onPreferenceChange(android.preference.Preference,%20java.lang.Object))`(`[Preference](/reference/android/preference/Preference)` preference, `[Object](/reference/java/lang/Object)` newValue) ` Called when a Preference has been changed by the user. |\n\nPublic methods\n--------------\n\n### onPreferenceChange\n\nAdded in [API level 1](/guide/topics/manifest/uses-sdk-element#ApiLevels) \n\n```\npublic abstract boolean onPreferenceChange (Preference preference, \n Object newValue)\n```\n\nCalled when a Preference has been changed by the user. This is\ncalled before the state of the Preference is about to be updated and\nbefore the state is persisted.\n\n\u003cbr /\u003e\n\n| Parameters ||\n|--------------|---------------------------------------------------|\n| `preference` | `Preference`: The changed Preference. \u003cbr /\u003e |\n| `newValue` | `Object`: The new value of the Preference. \u003cbr /\u003e |\n\n| Returns ||\n|-----------|-----------------------------------------------------------------------|\n| `boolean` | True to update the state of the Preference with the new value. \u003cbr /\u003e |"]]