Итак, я пытаюсь сохранить самый высокий балл с помощью sharedPreferences, но у меня проблемы. Я не знаю, как бы я настроил его, чтобы получить максимальный результат и отобразить его.Показать рекордер с общими настройками?
У меня теперь будет отображаться текущий счет, который получает игрок. Вот то, что я до сих пор, что не работает:
public class GameOptions extends Activity {
int theScore;
TextView highScore;
public static String filename = "MyHighScore";
SharedPreferences spHighScore;
int dataReturned;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.in_game_menu);
TextView tvTheScore = (TextView) findViewById(R.id.textView2);
TextView highScore = (TextView) findViewById(R.id.high_score);
Bundle gotScore = getIntent().getExtras();
theScore = gotScore.getInt("scoreKey");
//String thisIsTheScoreToDisplay = theScore.toString();
tvTheScore.setText("SCORE: "+theScore);
spHighScore = getSharedPreferences(filename, 0);
SharedPreferences.Editor editor = spHighScore.edit();
editor.putInt("highScoreKey", theScore);
editor.commit();
int dataReturned = spHighScore.getInt("highScoreKey", 0);
highScore.setText("" + dataReturned);
btw Это для игры, и я пытаюсь сохранить только верхнюю оценку # 1, которая является просто int. Еще раз спасибо за любую помощь. – alexward1230