Delete SharedPreferences File

后端 未结 4 1977
南方客
南方客 2020-12-05 05:21

I am allowing the user to create multiple SharedPreferences files, but I also would like the option for them to delete these files. I know I could use internal

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-05 06:09

    If you get SharedPreferences instance via Context.getSharedPreferences("X"), then your file will be named X.xml.

    It will be located at /data/data/com.your.package.name/shared_prefs/X.xml. You can just delete that file from the location. Also check /data/data/com.your.package.name/shared_prefs/X.bak file, and if it exists, delete it too.

    But be aware, that SharedPreferences instance saves all data in memory. So you'll need to clear preferences first, commit changes and only then delete preferences backing file.

    This should be enough to implement your design decision.

提交回复
热议问题