我遇到了问题SharedPreferences
如果我想保存两个不同的值。我试着用这段代码:SharedPreferences覆盖其他值
SharedPreferences sharedPref = getSherlockActivity().getPreferences(Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPref.edit();
editor.putInt(getString(R.string.SavedStartSilentHour), hour);
editor.commit();
editor.putInt(getString(R.string.SavedStartSilentMinute), min);
editor.commit();
// One editor.commit() is enough
如果我运行这段代码,第一个值会被第二个值覆盖。如果我删除了第二部分,则值被正确保存。这是为什么?
发表您的'<字符串名称= “SavedStartSilentHour”>'被定义XML文件。 –
这就是谢谢你!有时你因为那么多树而看不到森林......谢谢。 – Cilenco
@ user2246674我想这将是一个很好的发表您的评论作为答案。 –