-4
Я делаю приложение (игру) в Android Studios и тестирую его, и все это работает, но одно. То есть, когда я делаю новый высокий балл, он либо не сохраняет должным образом, либо не отображается должным образом.Почему нет общих настроек, сохраняющих значения?
public GamePanel(Context context) {
super(context);
this.mContext = context;
}
//display
public void drawText(Canvas canvas) {
SharedPreferences prefs = mContext.getSharedPreferences("PrefsKeys", Context.MODE_PRIVATE);
int oldScore = prefs.getInt("highScore", 0);
int newScore = Player.getScore() * 3;
//update score only if new score is higher
if (newScore > oldScore) {
SharedPreferences.Editor editor = prefs.edit();
editor.putInt("highScore", 0);
editor.commit();
}
Paint paint = new Paint();
paint.setColor(Color.BLACK);
paint.setTextSize(30);
paint.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.BOLD));
canvas.drawText("DISTANCE: " + newScore, 10, HEIGHT - 10, paint);
canvas.drawText("HighScore: " + oldScore, WIDTH - 215, HEIGHT - 10, paint);