Initializing рекордами массив:Общие предпочтения не Сохранение данных
score = 0;
sharedPreferences = context.getSharedPreferences("Scores", Context.MODE_PRIVATE);
//initialize the array of high scores
highScore[0] = sharedPreferences.getInt("score1",0);
highScore[1] = sharedPreferences.getInt("score2",0);
highScore[2] = sharedPreferences.getInt("score3",0);
highScore[3] = sharedPreferences.getInt("score4",0);
highScore[4] = sharedPreferences.getInt("score5",0);
Проверка на 4 наивысшие значения:
highScore[5] = score;
Arrays.sort(highScore);
Это мой код для сохранения данных в общих настройках
SharedPreferences.Editor e = sharedPreferences.edit();
for(int j=4;j>=0;j--){
e.putInt("score"+(j+1),highScore[j]);
e.apply();
}
Пожалуйста, проверьте здесь: http://stackoverflow.com/questions/23024831/android-shared-preferences-example –
- это полный код для сохранения значения в настройках? –
Вы инициализировали sharedPreferences с помощью клавиши «Scores»? – Madhav