Android 从特定的SharedPreferences文件中检索所有存储的条目
示例
该getAll()方法从首选项中检索所有值。例如,我们可以使用它来记录的当前内容SharedPreferences:
private static final String PREFS_FILE = "MyPrefs";
public static void logSharedPreferences(final Context context) {
SharedPreferences sharedPreferences = context.getSharedPreferences(PREFS_FILE, Context.MODE_PRIVATE);
Map<String, ?> allEntries = sharedPreferences.getAll();
for (Map.Entry<String, ?> entry : allEntries.entrySet()) {
final String key = entry.getKey();
final Object value = entry.getValue();
Log.d("map values", key + ": " + value);
}
}该文档警告您有关修改Collection返回者getAll:
请注意,您不得修改此方法返回的集合,也不得更改其任何内容。如果这样做,则不能保证所存储数据的一致性。
热门推荐
10 姐妹结婚新婚祝福语简短
11 古文毕业赠言祝福语简短
12 工人励志祝福语大全简短
13 写给高考的祝福语简短
14 简短宝贝祝福语大全集
15 竞选班长祝福语简短精辟
16 艺校元旦祝福语大全简短
17 新年简短祝福语大全集
18 鸡脚结婚祝福语大全简短