Question

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!

Was it helpful?

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 .

OTHER TIPS

Did you register to receive onSharedPreferenceChanged callbacks?

Add this to your main activity's onCreate method (and make sure to implement onSharedPreferenceChanged):

PreferenceManager.getDefaultSharedPreferences(getBaseContext()).registerOnSharedPreferenceChangeListener(this);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top