您可以使用 SharedPreferences 来存储属于应用程序的数据。为 SharedPreferences 添加值//Whenever you update the score call this functionvoid updateScore(int score){ SharedPreferences mySharedPref = getSharedPreferences("give Any Name", Context.MODE_PRIVATE); SharedPreferences.Editor editor = mySharedPref.edit(); editor.putInt("score", score); editor.apply(); //this function will commit asynchronously}如果您需要随时获取分数,请调用此函数。//Whenever you update the score call this functionpublic int getScore(){ SharedPreferences mySharedPref = getSharedPreferences("give Any Name", Context.MODE_PRIVATE); return mySharedPref.getInt("score", -1); //-1 is the default value that is returned if the value is not set using putInt}