-
-
Save codeforfun-jp/a2e7ec17a579d63dc873a3960ee2c032 to your computer and use it in GitHub Desktop.
CTB 8-3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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