title: Saving state while rotation
body: <p>I Have an app in which the main activity shows a question and has true button false button and cheat button
  When user press the correct option, listener will Toast Correct.. and otherwise listener will Toast Incorrect</p>
  
  <p>Now when we press the cheat button new activity is launched and has a textview "Are you sure you want to cheat?", another textview which is blank and a show answer button..</p>
  
  <p>When user presses the show answer button , the blank text view is set to the answer of the question (as asked in the main activity)</p>
  
  <p>And when the user goes back the true and false button onClickListeners are now set to make a toast "Cheating is wrong"</p>
  
  <p>i have declared a boolean value which is set to false, the boolean value is set to True and i save it in the bundle so that when the user rotates the screen , the value of the variable is not overwritten on onCreate(..) method being recalled.. </p>
  
  <p>I tried debugging with break points in eclipse , the value is  not overridden still on main activity "Cheating is wrong" doesnt show up , it shows Correct or Incorrect..</p>
  
  <p>QuizActivity : Launcher Activity
  CheatActivity: Activity launched on onCreate
  TrueFalse activity : creating array of objects with fields (question and answer)</p>
  
  <p>Following is the code : QuizActivity.java (Launcher activity)</p>
  
  <pre><code>package com.mhrsolanki2020.geoquiz;
  
  import android.content.Intent;
  import android.os.Bundle;
  import android.support.v7.app.ActionBarActivity;
  import android.util.Log;
  import android.view.Menu;
  import android.view.MenuItem;
  import android.view.View;
  import android.view.View.OnClickListener;
  import android.widget.Button;
  import android.widget.TextView;
  import android.widget.Toast;
  
  public class QuizActivity extends ActionBarActivity {
  
  private Button mTrueButton, mFalseButton, mNextButton, mCheatButton;
  private TextView mQuestionTextView;
  private static final String KEY_INDEX = "index";
  private static final String TAG = "QuizActivity";
  private TrueFalse[] mQuestionBank = new TrueFalse[] {
          new TrueFalse(R.string.question_oceans, true),
          new TrueFalse(R.string.question_mideast, false),
          new TrueFalse(R.string.question_africa, false),
          new TrueFalse(R.string.question_americas, true),
          new TrueFalse(R.string.question_asia, true) };
  
  private int mCurrentIndex = 0;
  private boolean mIsCheater;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_quiz);
  
      mQuestionTextView = (TextView) findViewById(R.id.question_text_view);
  
      mTrueButton = (Button) findViewById(R.id.true_button);
      mTrueButton.setOnClickListener(new OnClickListener() {
  
          @Override
          public void onClick(View v) {
              checkAnswer(true);
          }
      });
  
      mFalseButton = (Button) findViewById(R.id.false_button);
      mFalseButton.setOnClickListener(new OnClickListener() {
  
          @Override
          public void onClick(View v) {
              checkAnswer(false);
  
          }
      });
  
      mNextButton = (Button) findViewById(R.id.next_button);
      mNextButton.setOnClickListener(new OnClickListener() {
  
          @Override
          public void onClick(View v) {
              mCurrentIndex = (mCurrentIndex + 1) % mQuestionBank.length;
  
              updateQuestion();
              mIsCheater=false;
  
          }
      });
  
      mCheatButton = (Button) findViewById(R.id.cheat_button);
      mCheatButton.setOnClickListener(new OnClickListener() {
  
          @Override
          public void onClick(View v) {
              Intent i = new Intent(QuizActivity.this, CheatActivity.class);
              boolean answer = mQuestionBank[mCurrentIndex].isTrueQuestion();
              i.putExtra(CheatActivity.EXTRA_ANSWER_IS_TRUE, answer);
              startActivityForResult(i, 0);
          }
      });
  
      if (savedInstanceState != null)
          mCurrentIndex = savedInstanceState.getInt(KEY_INDEX, 0);
  
      updateQuestion();
  
  }
  
  @Override
  public void onSaveInstanceState(Bundle savedInstanceState) {
      super.onSaveInstanceState(savedInstanceState);
      savedInstanceState.putInt(KEY_INDEX, mCurrentIndex);
  }
  
  private void updateQuestion() {
  
      int question = mQuestionBank[mCurrentIndex].getQuestion();
      mQuestionTextView.setText(question);
  
  }
  
  private void checkAnswer(boolean userPressedTrue) {
      boolean answerIsTrue = mQuestionBank[mCurrentIndex].isTrueQuestion();
      int messageResId = 0;
      if (mIsCheater) {
          messageResId = R.string.judgement_toast;
      } else {
          if (userPressedTrue == answerIsTrue) {
              messageResId = R.string.correct_toast;
          } else {
              messageResId = R.string.incorrect_toast;
          }
      }
          Toast.makeText(this, messageResId, Toast.LENGTH_LONG).show();
  
  }
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      // Inflate the menu; this adds items to the action bar if it is present.
      getMenuInflater().inflate(R.menu.quiz, menu);
      return true;
  }
  
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
      // Handle action bar item clicks here. The action bar will
      // automatically handle clicks on the Home/Up button, so long
      // as you specify a parent activity in AndroidManifest.xml.
      int id = item.getItemId();
      if (id == R.id.action_settings) {
          return true;
      }
      return super.onOptionsItemSelected(item);
  }
  
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
      if (data == null) {
          return;
      } else {
          mIsCheater = data.getBooleanExtra(CheatActivity.EXTRA_ANSWER_SHOWN,
                  false);
          Log.d(TAG, "Value of mIsCheater : " + mIsCheater);
      }
  }
  }
  </code></pre>
  
  <p>The following is the code : CheatActivity.java</p>
  
  <pre><code>package com.mhrsolanki2020.geoquiz;
  
  import android.app.Activity;
  import android.content.Intent;
  import android.os.Bundle;
  import android.view.View;
  import android.view.View.OnClickListener;
  import android.widget.Button;
  import android.widget.TextView;
  
  public class CheatActivity extends Activity {
  
  public static final String EXTRA_ANSWER_IS_TRUE = "com.mhrsolanki2020.geoquiz.anwer_is_true ";
  public static final String EXTRA_ANSWER_SHOWN = "com.mhrsolanki2020.geoquiz.answer_shown";
  public static final String EXTRA_IS_ANSWER_SHOWN = "com.mhrsolanki2020.geoquiz.answer_is_shown";
  boolean mCorrectAnswer;
  private TextView mAnswerTextView;
  private Button mShowAnswer;
  private Boolean mIsAnswerShown;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_cheat);
      mCorrectAnswer = getIntent().getBooleanExtra(EXTRA_ANSWER_IS_TRUE,
              false);
      mShowAnswer = (Button) findViewById(R.id.showAnswerButton);
      mAnswerTextView = (TextView) findViewById(R.id.answerTextView);
  
      if (savedInstanceState != null) {
          mIsAnswerShown = savedInstanceState.getBoolean(
                  EXTRA_IS_ANSWER_SHOWN, false);
      } else {
          mIsAnswerShown = false;
      }
  
      mShowAnswer.setOnClickListener(new OnClickListener() {
  
          @Override
          public void onClick(View v) {
              if (mCorrectAnswer) {
                  mAnswerTextView.setText(R.string.true_button);
  
              } else {
                  mAnswerTextView.setText(R.string.false_button);
              }
              setAnswerShownResult(true);
          }
      });
  
  }
  
  public void setAnswerShownResult(boolean isAnswerShown) {
      Intent data = new Intent();
      mIsAnswerShown = isAnswerShown;
  
      data.putExtra(EXTRA_ANSWER_SHOWN, mIsAnswerShown);
      setResult(RESULT_OK, data);
  }
  
  @Override
  protected void onSaveInstanceState(Bundle savedInstanceState) {
      savedInstanceState.putBoolean(EXTRA_IS_ANSWER_SHOWN, mIsAnswerShown);
  
  }
  
  }
  </code></pre>
  
  <p>Following is the code : TrueFalse.java
      package com.mhrsolanki2020.geoquiz;</p>
  
  <pre><code>public class TrueFalse {
  private int mQuestion;
  
  private boolean mTrueQuestion;
  
  public TrueFalse(int question, boolean trueQuestion) {
      mQuestion = question;
      mTrueQuestion = trueQuestion;
  
  }
  
  public int getQuestion() {
      return mQuestion;
  }
  
  public void setQuestion(int question) {
      mQuestion = question;
  }
  
  public boolean isTrueQuestion() {
      return mTrueQuestion;
  }
  
  public void setTrueQuestion(boolean trueQuestion) {
      mTrueQuestion = trueQuestion;
  }
  }
  </code></pre>