Search code examples
androidandroid-activitypreferencespreferenceactivity

Responding to preference updates in Android


I am calling a PreferenceActivity from another activity and then updating the application state (ie: changing the font size) on onActivityResult, based on the preference changes.

I was thinking it would be better to put the state update logic in the PreferenceActivity. That way I don't have the duplicate the logic in each activity that calls the PreferenceActivity.

What's the best or correct way to do this?


Solution

  • Have any Activity (or other component) that cares about preference changes register a preference change listener via registerOnSharedPreferenceChangeListener(). Then, when the preferences change by any means, they will find out about it and can react accordingly.