Search code examples
androidpreferenceactivity

Android PreferenceActivity - Switches back to default


I'm developing an app that sends messages depending of the categories you are subscribed.

To do so, I have implemented a PreferenceActivity where I add dynamically a SwitchPreference for each category as showed at the picture below.

snapshot android PreferenceActivity

The problem is that when I change the switches status, scroll down and then scroll up they go back to default status by their own.

Did anybody have the same problem?


Solution

  • This behaviour is caused by an Android bug for earlier versions of android 5 Lollipop.

    If you are developing for Android 4.X or below, you have two options:

    1 - Develop a custom SwitchPreference

    2 - Use Checkboxes instead.

    To do so, see this question related.