Search code examples
androidpreferencescheckboxpreference

Preferences & CheckBoxPreference


The documentation for the PreferenceActivity states "These preferences will automatically save to SharedPreferences as the user interacts with them." That being the case, if I subclass PreferenceActivity, invoke addPreferencesFromResource in onCreate, set some preferences in the UI I would expect that any changes made to my preferences should automagically be saved; and when I return to my preference screen later all preferences should be restored.

The reason I'm asking is CheckBoxPreference is not behaving as expected, assuming my understanding is correct of course. I would expect if I have a CheckBoxPreference the users selection should be saved automatically upon change. Is this not the case?

So can anyone please confirm my understanding or correct me if necessary?

I can create a custom preference screen where I handle all the changes in code but I'd prefer to use the recommended approach. I 'm just wondering if there is a bug.

Suffice it to say I am a wee bit frustrated at the moment.

BTW I'm developing against v2.0 of the api.


Solution

  • I would expect if I have a CheckBoxPreference the users selection should be saved automatically upon change. Is this not the case?

    This works fine, if they make a positive selection. If they visit your activity and do not touch a CheckboxPreference, it will remain at the default.