Another Bug


#1

Hello everyone, I’v worked out all three challenges after, but I find a new cheat bug. Let’s say, if you cheated a question, then you can just press the Cheat button again, but NOT press the Show Answer button, then you’ll find the question you’ve cheated is now uncheat again!
I try to use putExtra method which param is booleanarray, and modify the CheatActivity, but it seems nothing change. :confused:

I need your help :question:


#2

Ha, great catch! Seems someone is always trying to game the system :laughing: Had to scratch my head for a bit on trying to plug this loophole. Short of keeping track of the index and making sure that they were still on the same question and mIsCheater was still true, I came up with this solution:

In CheatActivity, create a new Intent Extra key and boolean field:

public static final String EXTRA_HAS_CHEATED = 
	"com.bignerdranch.android.geoquiz.answer_cheated";

private boolean mAnswerShown;

Then set the boolean in the onClick handler for the “Show Answer” button:

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); } mAnswerShown = true; setAnswerShownResult(true); } });

Finally, override the onBackPressed event handler in CheatActivity - this calls setAnswerShownResult if the user tries to be slick and not press the “Show Answer” button":

@Override public void onBackPressed() { boolean cheated = getIntent().getBooleanExtra(EXTRA_HAS_CHEATED, false); if (cheated && !mAnswerShown) setAnswerShownResult(true); super.onBackPressed(); }

Then in QuizActivity, modify the onClick handler to set the Intent Extra with the mIsCheater field to communicate to CheatActivity is the user has previously cheated:

mCheatButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(QuizActivity.this, CheatActivity.class); boolean answertIsTrue = mQuestionBank[mCurrentIndex].isTrueQuestion(); i.putExtra(CheatActivity.EXTRA_ANSWER_IS_TRUE, answertIsTrue); i.putExtra(CheatActivity.EXTRA_HAS_CHEATED, mIsCheater); startActivityForResult(i, 0); } });

Also be certain that you are only clearing (setting to false) the mIsCheater field in QuizActivity in the onClick handlers for previous and next buttons. I was also clearing it upon entry into the onCreate method, which will foil your efforts. Certainly, not the most elegant solution, but it should keep those cheaters in line for the time being :wink: