Skip to content

Instantly share code, notes, and snippets.

@codeforfun-jp
Created June 9, 2021 01:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codeforfun-jp/a2e7ec17a579d63dc873a3960ee2c032 to your computer and use it in GitHub Desktop.
Save codeforfun-jp/a2e7ec17a579d63dc873a3960ee2c032 to your computer and use it in GitHub Desktop.
CTB 8-3
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_result);
TextView scoreLabel = findViewById(R.id.scoreLabel);
TextView highScoreLabel = findViewById(R.id.highScoreLabel);
int score = getIntent().getIntExtra("SCORE", 0);
scoreLabel.setText(score + "");
SharedPreferences sharedPreferences = getSharedPreferences("GAME_DATA", MODE_PRIVATE);
int highScore = sharedPreferences.getInt("HIGH_SCORE", 0);
if (score > highScore) {
highScoreLabel.setText("High Score : " + score);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putInt("HIGH_SCORE", score);
editor.apply();
} else {
highScoreLabel.setText("High Score : " + highScore);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment