Skip to content Skip to sidebar Skip to footer

Save Switch Button State, And Recover State With Sharedprefs

I have a Settings class so the user can decide to subscribe/unsubscribe to channels in Parse Push. I think I got it all figure out except for the part to recover, and maintain the

Solution 1:

Override the onCreate method of that activity class and attempt to load the values you saved in SharedPreferences.

krspush.setChecked(sharedPrefs.getBoolean("onKrsClick",false));

Solution 2:

  1. findviewbyid will crash unless called after the view is created ie, in the oncreate method.
  2. Consider using click listener on your switches.
  3. I don't see the point of this line of code "SharedPreferences sharedPrefs = getSharedPreferences("SwitchButton", MODE_PRIVATE)"
  4. Here is how you use shared preferences : https://stackoverflow.com/a/23024962/2590252
  5. You better look into some samples to learn about best coding practices http://developer.android.com/samples/index.html

Post a Comment for "Save Switch Button State, And Recover State With Sharedprefs"