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.
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.
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](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \nDeprecated in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)\n\nOnPreferenceChangeListener\n==========================\n\n*** ** * ** ***\n\nKotlin \\|[Java](/reference/android/preference/Preference.OnPreferenceChangeListener \"View this page in Java\") \n\n```\ninterface OnPreferenceChangeListener\n```\n\n|---------------------------------------------------------------|\n| [android.preference.Preference.OnPreferenceChangeListener](#) |\n\n*** ** * ** ***\n\n| **This interface was deprecated in API level 29.**\n|\n| Use the [AndroidX](https://developer.android.com/jetpack/androidx.html) [Preference Library](https://developer.android.com/reference/androidx/preference/package-summary.html) for consistent behavior across all devices. For more information on using the AndroidX Preference Library see [Settings](https://developer.android.com/guide/topics/ui/settings.html).\n\nInterface definition for a callback to be invoked when the value of this [Preference](/reference/kotlin/android/preference/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.\n\nSummary\n-------\n\n| Public methods ||\n|---------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| abstract [Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html) | [onPreferenceChange](#onPreferenceChange(android.preference.Preference,%20kotlin.Any))`(`preference:` `[Preference](/reference/kotlin/android/preference/Preference)!`, `newValue:` `[Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)!`)` Called when a Preference has been changed by the user. |\n\nPublic methods\n--------------\n\n### onPreferenceChange\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nabstract fun onPreferenceChange(\n preference: Preference!, \n newValue: Any!\n): Boolean\n```\n\n**Deprecated:** *Deprecated in Java.*\n\nCalled 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.\n\n| Parameters ||\n|--------------|---------------------------------------------------------------------------------------------------------------|\n| `preference` | [Preference](/reference/kotlin/android/preference/Preference)!: The changed Preference. |\n| `newValue` | [Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)!: The new value of the Preference. |\n\n| Return ||\n|------------------------------------------------------------------------------------|----------------------------------------------------------------|\n| [Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html) | True to update the state of the Preference with the new value. |"]]