Complete the code to save the state of the counter across configuration changes using rememberSaveable.
var counter by [1] { mutableStateOf(0) }
Using rememberSaveable() ensures the counter value is saved and restored across configuration changes like screen rotations.
Complete the code to create a button that increments the counter saved with rememberSaveable.
Button(onClick = { counter [1] 1 }) {
Text("Increment")
}The += operator increases the counter by 1 each time the button is clicked.
Fix the error in the code to properly save a String state across configuration changes.
var name by [1] { mutableStateOf("") }
rememberSaveable() is needed to save the String state across configuration changes, unlike remember().
Fill both blanks to create a rememberSaveable state for a Boolean flag and toggle it on button click.
var isChecked by [1] { mutableStateOf(false) } Button(onClick = { isChecked = ![2] }) { Text("Toggle") }
The Boolean state isChecked is saved with rememberSaveable() and toggled by negating its current value.
Fill all three blanks to create a rememberSaveable state for a String, update it on text input, and display it.
var text by [1] { mutableStateOf("") } TextField(value = [2], onValueChange = { [3] = it }) Text(text = text)
The String state text is saved with rememberSaveable(), updated on input change, and displayed below.