删除文件后Android共享首选项仍然可见 [英] Android Shared Preference Still visible after Deleting File
问题描述
我正在尝试使用共享首选项的应用程序.当我使用 Android 监视器从 data/data/com.your.package.name/shared_prefs/mySharedPref.xml 手动删除首选项文件时,该应用程序仍然能够读取首选项值.
I am trying an application where I am using Shared Preference. When I delete the preference file from data/data/com.your.package.name/shared_prefs/mySharedPref.xml manually using Android monitor, still the app is able to read the preference values.
我假设某些值是如何保留在手机的主存储器中的.我是否正确&清除共享偏好完全不留痕迹的可行解决方案是什么.但有一件事我只想在文件被擦除时清除首选项.为此,我需要检查文件是否存在,还有其他方法而不是检查 File 类吗?
I am assuming that some how the value is retained in main memory of the phone. Am I correct & what is the viable solution to clear shared preferences totally leaving no traces. But one thing I want to clear preference only if the file is wiped. For this I need to check presence of file, Any other approach rather than checking with File class ?
推荐答案
要删除特定值:SharedPreferences.Editor.remove()
后跟一个 commit()
To remove specific values: SharedPreferences.Editor.remove()
followed by a commit()
将它们全部删除 SharedPreferences.Editor.clear()
后跟 commit()
To remove them all SharedPreferences.Editor.clear()
followed by a commit()
您使用 remove() 删除特定首选项,使用 clear() 删除所有首选项.
在SharedPreferences.Editor<上查看官方文档/a>.
Checkout official documentation on SharedPreferences.Editor.
这篇关于删除文件后Android共享首选项仍然可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!