SharedPreferences are sometimes deleted

前端 未结 3 792
名媛妹妹
名媛妹妹 2020-12-29 05:48

My app uses SharedPreferences (with the help of a PreferenceActivity) to store all settings. But sometimes all settings are deleted and all values are set back to default. M

3条回答
  •  北荒
    北荒 (楼主)
    2020-12-29 06:14

    I found out the reason why the settings disappear: If two processes write data to SharedPreferences, it can happen that all SharedPreferences are reset to default values. In my case all settings are cleared when the service write the first data to SharedPreferences.

    Now, the service provides only read access to the SharedPreferences. The settings that are accessed by both processes writing are stored in a database.

提交回复
热议问题