如何检查SharedPreferences是否存在 [英] How to check if SharedPreferences exists or not
本文介绍了如何检查SharedPreferences是否存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在以这种方式检查文件是否存在,但是我需要进一步检查,我需要知道是否有一个文件,有什么办法吗?
I'm checking in this way if the file exists, but I need to go beyond, I need to know if there is one in specific, is there any way?
File f = new File("/data/data/com.eventrid.scanner/shared_prefs/Eventrid.xml");
if (f.exists()){
}
else{
}
推荐答案
SharedPreferences
具有contains(String key)
方法,可用于检查具有给定键的条目是否存在.
SharedPreferences
has a contains(String key)
method, which can be used to check if an entry with the given key exists.
http://developer.android.com/reference/android/content/SharedPreferences.html
这篇关于如何检查SharedPreferences是否存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文