First Challenge : Closing loophole (Simple solution I guess)

hello hello…
maybe I made the simple solution that works…

I set a default boolean value (false)

private var cheaterStatus = false

and used it inside the onClickListiner to change it to true in case the button was clicked

 showAnswerButton.setOnClickListener {
        val answerText = when{
            answerIsTrue -> R.string.true_button
            else -> R.string.false_button
        //create a function to return the result to MainActivity
        cheaterStatus = true

Then i saved the result by overriding the onSave… function

 override fun onSaveInstanceState(savedInstanceState: Bundle) {
        Log.d(BOOLEAN_KEY, "onSave called.")

and obviously retrieved it onCreate…

   //saving the status on configuration change.
        val cheatStatus = savedInstanceState?.getBoolean(BOOLEAN_KEY, false) ?: false

and re-displayed the text of the answer if the retrieved boolean was true

  //if answer is true, show the text again
        if (cheatStatus) {
            val answerText = when {
                answerIsTrue -> R.string.true_button
                else -> R.string.false_button


1 Like

The only problem I have is that when I rotate the device, the boolean text value dissapears but its still there

can’t get you… how did you saved it?

I saved it as a Boolean

share your code…
after you get the boolean from the savedInstanceState you should reassign local values with it and display the message again using the when

Okay give me some time I will do that