我看到这个堆栈Need to save a high score for an Android game保存int的共享首选项?
这就是它告诉我
//setting preferences
SharedPreferences prefs = this.getSharedPreferences("myPrefsKey", Context.MODE_PRIVATE);
Editor editor = prefs.edit();
editor.putInt("key", score);
editor.commit();
//getting preferences
SharedPreferences prefs = this.getSharedPreferences("myPrefsKey", Context.MODE_PRIVATE);
int score = prefs.getInt("key", 0); //0 is the default value
我在想,应该“键”可以在字符串,其中高分所在?这是否与我命名我的首选项密钥有关? 谢谢你的时间。
是的,关键必须是字符串,名称并不重要 – 3xplore