The First Challenge Problem


#1

[code]package com.example.quize;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class CheatActivity extends Activity {
public static final String EXTRA_ANSWER_IS_TRUE=
“com.example.quize.answer_is_true”;
public static final String EXTRA_ANSWER_SHOWN =
“com.bignerdranch.android.geoquiz.answer_shown”;
public static final String CHEATED_AFTER_ROTATION=
“com.bignerdranch.android.geoquiz.Rotation”;
public static final String EXTRA_IS_CHEAT=“com.bignerdranch.android.geoquiz.is_cheat”;
private boolean mAnswerIsTrue;
private boolean mIsCheat;
private TextView mAnswerTextView;
private Button mShowAnswer;
private boolean mCheatedRotation = false;
private static final String TAG = “CheatActivity”;

private void setAnswerShownResult(boolean isAnswerShown) {
	mCheatedRotation=true;
	Intent data = new Intent();
	data.putExtra(EXTRA_ANSWER_SHOWN, isAnswerShown);
	setResult(RESULT_OK, data);
	}
protected void onCreate(Bundle savedInstanceState){
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_cheat);
	
	
	if (savedInstanceState != null) {
		mCheatedRotation= savedInstanceState.getBoolean(CHEATED_AFTER_ROTATION);
		
	}
      Log.d(TAG, "1. value of mAnswerTrue in onCreate(): " + mAnswerIsTrue);
      Log.d(TAG, "1. value of mCheatedRotation in onCreate(): " + mCheatedRotation);
      setAnswerShownResult(false);
      
      mAnswerIsTrue=getIntent().getBooleanExtra(EXTRA_ANSWER_IS_TRUE, false);
      
	 mAnswerTextView=(TextView)findViewById(R.id.textView1);
	 
	if (mCheatedRotation==false)
	 {
		mShowAnswer=(Button)findViewById(R.id.showAnswerButton);

		
	 mShowAnswer.setOnClickListener(new View.OnClickListener() {
				
				@Override
				public void onClick(View v) {
					if (mAnswerIsTrue)
						{mAnswerTextView.setText(R.string.true_button);}
					else
						{mAnswerTextView.setText(R.string.false_button);}
					
					setAnswerShownResult(true);
				}
			});
	 }
	else
	{
		if (mAnswerIsTrue)
		{mAnswerTextView.setText(R.string.true_button);}
		else
		{mAnswerTextView.setText(R.string.false_button);}
	
	setAnswerShownResult(true);
	}
	 
	 



	

}

public void onStart(){
	super.onStart();



	Log.d(TAG, "2. onStart() called");
}
public void onPause(){
	super.onPause();
	


setAnswerShownResult(true);
	Log.d(TAG, "4. onPause() called");
}
public void onResume(){
	super.onResume();
	 
	Log.d(TAG, "3. onResume() called");
}
public void onStop(){
	super.onStop();
	Log.d(TAG, "5. onStop() called");
}
public void onDestroy(){
	super.onDestroy();
	Log.d(TAG, "6. onDestroy() called");
}
public void onSaveInstanceState(Bundle savedInstanceState){
	super.onSaveInstanceState(savedInstanceState);
	Log.i(TAG, "onSaveInstanceState");
	savedInstanceState.putBoolean(CHEATED_AFTER_ROTATION, mCheatedRotation);
	Log.d(TAG, "value of mCheatedRotation in onSaveInstanceState(): " + mCheatedRotation);
}

}
[/code]

I try a couple hours to figure out this the first challenge, I try a lot solutions been post in this forum, there is no any can help me. Do you have anyone can help me look at this code?/

Thanks


#2

Hi,
one of the problems that stands out in your code is this part.

[code] if (savedInstanceState != null) {
mCheatedRotation= savedInstanceState.getBoolean(CHEATED_AFTER_ROTATION);

  }[/code]

It seems like you need to provide a value to pair with the key: “CHEATED_AFTER_ROTATION” (would be mCheatedRotation).