Shared Preferences get lost after shutting down device or killing the app

前端 未结 3 1009
礼貌的吻别
礼貌的吻别 2020-12-06 05:57

there are lots of questions out there related to shared preferences and the alternatives. My problem: when I shut down the device or kill the app, the shared preferences get

3条回答
  •  感动是毒
    2020-12-06 06:36

    I was having the exact same issue when using string set with the SharedPreferences. I discovered why this was happening and how to resolve it.

    Very important to read the API documentation for SharedPreferences.getStringSet (String key, Set defValues)

    Essentially DON'T modify or touch the returned Set! If you do you will get odd results with the SharedPreferences. :)

    Enjoy!

提交回复
热议问题