Search code examples
androidpreferencessharedpreferences

How do I capture changes of a CheckBoxPreference in android development?


I'm trying to learn how to do live wallpapers for android. I've got it working and now I want to add a couple preferences. So, I've created a preference activity and followed all the examples I could find.

I can capture ListBoxPreferences just fine, but the 'onSharedPreferenceChanged' method is never called when a checkbox has been changed.

Is there extra code that has to be added for capturing checkbox changes? Is there a best practices way of doing check boxes in preferences?

I've been banging my head against this issue for two days, any help would be GREATLY appreciated!

Thanks!


Solution

  • @Josh - Good answer.

    I'd like to add for the sake of completeness is that you should set things up so you register for changes in your PreferenceActivity's onResume() method and unregister in the onPause() method.

    The answer to this question has a good sample of code taken from on the the stock Android example programs.

    Alternatively, you can also register listeners for each of the preferences in your activity's onCreate() and handle events on them separately .