I am having issues with persisting questionBank after screen rotation with SavedStateHandle.
From Question.kt:
package com.bignerdranch.android.geoquiz
import androidx.annotation.StringRes
data class Question(@StringRes val textResId: Int, val answer: Boolean, var answered: Boolean = false)
Specifically, using the SavedStateHandle I don’t see how to persist the answered
field in my class. The answered
field was created as part of the challenge from Chapter 3 (Challenge: Preventing Repeat Answers)
Using the SavedStateHandle framework, would this be the correct implementation to get
the field?
var currentQuestionAnswered: Boolean
get() = questionBank[currentIndex].answered
My problem is with setting questionBank[currentIndex].answered
after a question has been answered and persisting the updated questionBank[currentIndex].answered
value using SavedStateHandle. Using set(value: Boolean) = savedStateHandle.set(CURRENT_INDEX_KEY, true)
is not correct as questionBank
is not referenced.
Would onSavedInstanceState
be the right approach here? Trying to avoid that as that would cause confusion in the implementation.
Would appreciate the help!