Save SWITCH button state, and recover state with SharedPrefs

前端 未结 2 886
误落风尘
误落风尘 2021-01-16 18:27

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, a

相关标签:
2条回答
  • 2021-01-16 19:07
    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
    0 讨论(0)
  • 2021-01-16 19:17

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

    krspush.setChecked(sharedPrefs.getBoolean("onKrsClick",false));
    
    0 讨论(0)
提交回复
热议问题