Skip to content

Instantly share code, notes, and snippets.

Last active September 19, 2023 08:13
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
QuizApp 4.1
protected void onCreate(Bundle savedInstanceState) {
TextView resultLabel = findViewById(;
TextView totalScoreLabel = findViewById(;
// 正解数を取得
int score = getIntent().getIntExtra("RIGHT_ANSWER_COUNT", 0);
// トータルスコアの読み出し
SharedPreferences prefs = getPreferences(Context.MODE_PRIVATE);
int totalScore = prefs.getInt("TOTAL_SCORE", 0);
// トータルスコアに今回のスコアを加算
totalScore += score;
// TextViewに表示する
resultLabel.setText(getString(R.string.result_score, score));
totalScoreLabel.setText(getString(R.string.result_total_score, totalScore));
// トータルスコアを保存
SharedPreferences.Editor editor = prefs.edit();
editor.putInt("TOTAL_SCORE", totalScore);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment