如果您只需要存储一个整数,则SharedPreferences最适合您使用:
//setting preferencesSharedPreferences prefs = this.getSharedPreferences("myPrefsKey", Context.MODE_PRIVATE);Editor editor = prefs.edit();editor.putInt("key", score);editor.commit();获得首选项:
//getting preferencesSharedPreferences prefs = this.getSharedPreferences("myPrefsKey", Context.MODE_PRIVATE);int score = prefs.getInt("key", 0); //0 is the default value当然,用
"key"高分值
"myPrefsKey"的键和您的偏好的键替换(这些可以是任意的。将它们设置为可识别且独特的东西是很好的)。



