结算preferences共享preferences在Android中,而不仅仅是值 [英] Clearing preferences in SharedPreferences in Android, not just Values
问题描述
这是我承担了共享preferences文档什么的,我可以更新preference,添加一个或清除共享preference文件中的所有preference值。
from what I can incur out of the SharedPreferences documentation, I can update a preference, add one or clear all preference values in a shared preference file.
但我想彻底清除这里的一切都共享preference文件,而不仅仅是值,但preferences他们指的也是如此。
But I want to completely clear everything inside a shared preference file, not just the values, but the preferences they refer to as well.
推荐答案
如果你有一个共享preferences.Editor
对象,并调用明确()
,这难道不是得到你想要的东西?这将删除所有preferences如果调用共享pref.getAll()
它应该给你的大小为0 [我只是测试这种]的地图。
If you have a SharedPreferences.Editor
object and you call clear()
, does this not get you what you want? It will remove all preferences and if you call sharedPref.getAll()
it should give you a map of size 0 [I just tested this].
要删除一个特定的preference,叫 editor.remove(preF)
,其中preF是preference名。
To remove one specific preference, call editor.remove(pref)
, where pref is the preference name.
PS:不要忘记调用commit提交更改()或apply()方法的编辑器。申请()更快,因为它是异步的。提交()是同步的,但返回一个布尔值,指示提交成功。
PS: Don't forget to commit your changes by calling commit() or apply() method on the editor. apply() is faster as it is asynchronous. commit() is synchronous but returns a boolean indicating if the commit succeeded.
这篇关于结算preferences共享preferences在Android中,而不仅仅是值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!