On screen rotation, I would like to have the var cardcount saved, so the user is not reset to to the first flash card when they rotate the screen.
I have attempted using the onSaveInstanceState and savedInstanceState.getInt() to keep the keep the value on the rotation, but it does not save the value.
I have seen alternatives to these functions, and I am not sure if I am going down some deep rabbit holes for something simple, or if I am swimming in the wrong ocean entirely.
Should I be looking into ViewModels and persistent storage, taking over manually with configuration changes, or shared preferences? The data is one variable, in one fragment.
class Components : Fragment() {
//Variables to keep track of which card, as well as which side is showing
private var cardcount = 0
private var cardfront = true
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
//This is the function to set the image and text for the front and back of the flashard
fun select_card() {
card_front.setImageResource(map.getValue(cardcount).image)
card_back.text = map.getValue(cardcount).text
}
}
That's what ViewModel is for.
As per android docs:
https://developer.android.com/topic/libraries/architecture/viewmodel