狐的传说
你有两个选择,我会把选择留给你。共享首选项这是Android独有的框架,允许您在键值框架中存储原始值(例如int,boolean,并且String严格来说,String这不是原始的)。这意味着您为值指定一个名称,例如“homeScore”并将值存储到此键。SharedPreferences settings = getApplicationContext().getSharedPreferences(PREFS_NAME, 0);SharedPreferences.Editor editor = settings.edit();editor.putInt("homeScore", YOUR_HOME_SCORE);// Apply the edits!editor.apply();// Get from the SharedPreferencesSharedPreferences settings = getApplicationContext().getSharedPreferences(PREFS_NAME, 0);int homeScore = settings.getInt("homeScore", 0);内部存储器在我看来,这是你可能正在寻找的。您可以将任何想要的内容存储到文件中,这样可以提供更大的灵活性。但是,该过程可能比较棘手,因为所有内容都将存储为字节,这意味着您必须小心保持读写过程协同工作。int homeScore;byte[] homeScoreBytes;homeScoreBytes[0] = (byte) homeScore;homeScoreBytes[1] = (byte) (homeScore >> 8); //you can probably skip these two homeScoreBytes[2] = (byte) (homeScore >> 16); //lines, because I've never seen a //basketball score above 128, it's //such a rare occurance.FileOutputStream outputStream = getApplicationContext().openFileOutput(FILENAME, Context.MODE_PRIVATE);outputStream.write(homeScoreBytes);outputStream.close();现在,您也可以查看外部存储,但我不建议在这种特殊情况下,因为外部存储可能不会在以后存在。(注意,如果你选择它,它需要一个权限)