title: Multiple Choice Quiz app with SQLite (score are not show in new activity)
body: <p>I'm new to android and I'm just doing a android app by watching Multiple choice quiz app with sqlite integration series(Youtube Playlist). Now I have a problem. In the tutorial, they have 2 activity( <strong>Main Activity</strong> &amp; <strong>Quiz Activity</strong>) and the score from QuizActivity are send back to MainActivity. But  I Have 3 Activity(<strong>Main Activity</strong> ,<strong>QuestionActivity</strong> &amp; <strong>ResultActivity</strong>). I want to send the score from QuestionActivity to ResultActivity and show it with textView. The problem is score are always show as 0 but when I debug the <code>showResult()</code>, there score are showing <strong>Debug Result</strong>.Can you please check my coding and please fix it for me.I'm really new to android so please help me guys.</p>
  
  <blockquote>
    <p>This is the debug result.</p>
  </blockquote>
  
  <p><img src="https://i.stack.imgur.com/0b7Bl.png" alt="Debug result"></p>
  
  <p><strong>MainActivity</strong></p>
  
  <pre><code>package com.enkoala.enkoala;
  
  import android.content.Intent;
  import android.support.v7.app.AppCompatActivity;
  import android.os.Bundle;
  import android.view.View;
  import android.widget.Button;
  
  public class MainActivity extends AppCompatActivity {
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      Button buttonGeneral= findViewById(R.id.button_general_english);
      buttonGeneral.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View view) {
              GeneralEnglish();
          }
      });
  }
  private void GeneralEnglish(){
      Intent intent=new Intent(MainActivity.this,QuestionActivity.class);
      startActivity(intent);
  }
  }
  </code></pre>
  
  <p><strong>QuestionActivity</strong></p>
  
  <pre><code>package com.enkoala.enkoala;
  
  import android.content.Intent;
  import android.content.SharedPreferences;
  import android.content.res.ColorStateList;
  import android.support.annotation.Nullable;
  import android.support.v7.app.AppCompatActivity;
  import android.os.Bundle;
  import android.view.View;
  import android.widget.Button;
  import android.widget.RadioButton;
  import android.widget.RadioGroup;
  import android.widget.TextView;
  import android.widget.Toast;
  
  import java.util.Collections;
  import java.util.List;
  
  
  public class QuestionActivity extends AppCompatActivity {
  public   static final int REQUEST_CODE_QUIZ = 1;
  
  public static final String EXTRA_SCORE="extra_score";
  
  
  private TextView textViewQuestion;
  private TextView textViewQuestionCount;
  private RadioGroup radioGroup;
  private RadioButton radioButton1;
  private RadioButton radioButton2;
  private RadioButton radioButton3;
  private Button buttonNext;
  
  private ColorStateList textColorDefaultRb;
  
  private List&lt;Question&gt; questionList;
  
  private int questionCounter;
  private int questionCountTotal;
  private Question currentQuestion;
  
  private int score;
  private boolean answered;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_question);
  
      textViewQuestion= findViewById(R.id.text_view_question);
      textViewQuestionCount= findViewById(R.id.text_view_question_count);
      radioGroup= findViewById(R.id.radio_group);
      radioButton1= findViewById(R.id.radio_button1);
      radioButton2= findViewById(R.id.radio_button2);
      radioButton3= findViewById(R.id.radio_button3);
      buttonNext= findViewById(R.id.button_next);
  
      QuizDatabseHelper databseHelper=new QuizDatabseHelper(this);
      questionList=databseHelper.getAllQuestions();
      questionCountTotal=questionList.size();
      Collections.shuffle(questionList);
  
      showNextQuestion();
  
      buttonNext.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View view) {
              if (!answered){
                  if (radioButton1.isChecked() || radioButton2.isChecked() || radioButton3.isChecked()){
                      checkAnswer();
                  }else {
                      Toast.makeText(QuestionActivity.this, "Please select an answer",                                                     Toast.LENGTH_SHORT).show();
                  }
              }else {
                  showNextQuestion();
              }
          }
      });
      }
      private void showNextQuestion(){
      radioGroup.clearCheck();
  
      if (questionCounter&lt;questionCountTotal){
          currentQuestion=questionList.get(questionCounter);
          textViewQuestion.setText(currentQuestion.getQuestion());
          radioButton1.setText(currentQuestion.getOption1());
          radioButton2.setText(currentQuestion.getOption2());
          radioButton3.setText(currentQuestion.getOption3());
  
          questionCounter++;
          textViewQuestionCount.setText("Question: "+ questionCounter + "/" + questionCountTotal);
          answered=false;
          buttonNext.setText("Next");
      }else {
          buttonNext.setText("Get Result");
          showResult();
      }
      }
      public void showResult(){
          Intent resultIntent = new Intent(QuestionActivity.this,ResultActivity.class);
          resultIntent.putExtra(EXTRA_SCORE,score);
          setResult(RESULT_OK,resultIntent);
          startActivityForResult(resultIntent,REQUEST_CODE_QUIZ);
      }
  
  
      private void checkAnswer(){
      answered=true;
  
      RadioButton radioButtonselected=findViewById(radioGroup.getCheckedRadioButtonId());
      int answernumber = radioGroup.indexOfChild(radioButtonselected) + 1;
      if (answernumber == currentQuestion.getAnswernumber()){
          score++;
      }
      showNextQuestion();
      }
  }
  </code></pre>
  
  <p><strong>ResultActivity</strong></p>
  
  <pre><code>package com.enkoala.enkoala;
  
  import android.content.Intent;
  import android.content.SharedPreferences;
  import android.support.annotation.Nullable;
  import android.support.v7.app.AppCompatActivity;
  import android.os.Bundle;
  import android.view.View;
  import android.widget.Button;
  import android.widget.TextView;
  
  import static com.enkoala.enkoala.QuestionActivity.REQUEST_CODE_QUIZ;
  
  public class ResultActivity extends AppCompatActivity {
  
  public static final String SHARED_PREFS = "sharedPrefs";
  public static final String KEY_HIGHSCORE = "keyhighscore";
  private TextView textViewHighscore;
  private int highscore;
  
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_result);
  
      textViewHighscore = findViewById(R.id.text_view_score);
      loadHighscore();
  
      final Button buttonback = findViewById(R.id.button_back);
      buttonback.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View view) {
              buttonBack();
          }
      });
  
  }
  
  private void buttonBack() {
      Intent intent = new Intent(ResultActivity.this, MainActivity.class);
      startActivity(intent);
  }
  
  protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
      super.onActivityResult(requestCode, resultCode, data);
  
      if (requestCode == REQUEST_CODE_QUIZ) {
          if (resultCode == RESULT_OK) {
              int score = data.getIntExtra(QuestionActivity.EXTRA_SCORE, 0);
              if (score &gt; highscore) {
                  updateHighscore(score);
              }
          }
      }
  }
  
  private void loadHighscore() {
      SharedPreferences sharedPreferences = getSharedPreferences(SHARED_PREFS, MODE_PRIVATE);
      highscore = sharedPreferences.getInt(KEY_HIGHSCORE, 0);
      textViewHighscore.setText("Your score is " + highscore + " out of 25. ");
  }
  
  private void updateHighscore(int highscoreNew) {
      highscore = highscoreNew;
      textViewHighscore.setText("Your score is " + highscore + " out of 25. ");
      SharedPreferences sharedPreferences = getSharedPreferences(SHARED_PREFS, MODE_PRIVATE);
      SharedPreferences.Editor editor = sharedPreferences.edit();
      editor.putInt(KEY_HIGHSCORE, highscore);
      editor.apply();
  }
  </code></pre>
  
  <p>}</p>