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
}
answerTextView.setText(answerText)
//create a function to return the result to MainActivity
setAnswerShownResult(true)
cheaterStatus = true
}
Then i saved the result by overriding the onSave… function
override fun onSaveInstanceState(savedInstanceState: Bundle) {
super.onSaveInstanceState(savedInstanceState)
Log.d(BOOLEAN_KEY, "onSave called.")
savedInstanceState.putBoolean(BOOLEAN_KEY,cheaterStatus)
}
and obviously retrieved it onCreate…
//saving the status on configuration change.
val cheatStatus = savedInstanceState?.getBoolean(BOOLEAN_KEY, false) ?: false
setAnswerShownResult(cheatStatus)
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
}
answerTextView.setText(answerText)
}
IT WORKED!