删除共享preferences文件文件、preferences

由网友(娜么美)分享简介:我允许用户创建多个共享preferences 的文件,但我也想为他们删除这些文件的选项。我知道我可以使用内部存储,但是这不是我的问题。 I am allowing the user to create multiple SharedPreferences files, but I also would like th...

我允许用户创建多个共享preferences 的文件,但我也想为他们删除这些文件的选项。我知道我可以使用内部存储,但是这不是我的问题。

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 storage, but that is not my question.

我的问题是:我如何才能删除(不只是清除)共享preferences 文件

My question is: "How can I delete (not just clear) a SharedPreferences file?"

推荐答案

如果您通过获得共享preferences 例如 Context.getShared preferences(X),那么你的文件将被命名为 X.xml

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

这将是位于 /data/data/com.your.package.name/shared_$p$pfs/X.xml 。您只需删除该位置的文件。同时检查 /data/data/com.your.package.name/shared_$p$pfs/X.bak 文件,如果存在,将其删除了。

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.

但要注意,即共享preferences 实例保存所有的数据在内存中。所以,你需要先清除preferences,提交更改,然后才删除preferences备份文件。

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.

阅读全文

相关推荐

最新文章