0
0
Android Kotlinmobile~10 mins

rememberSaveable for configuration changes in Android Kotlin - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to save the state of the counter across configuration changes using rememberSaveable.

Android Kotlin
var counter by [1] { mutableStateOf(0) }
Drag options to blanks, or click blank then click option'
AstateOf()
BrememberSaveable()
CmutableStateOf()
Dremember()
Attempts:
3 left
💡 Hint
Common Mistakes
Using remember() instead of rememberSaveable() causes state loss on rotation.
Using mutableStateOf() alone does not save state across configuration changes.
2fill in blank
medium

Complete the code to create a button that increments the counter saved with rememberSaveable.

Android Kotlin
Button(onClick = { counter [1] 1 }) {
    Text("Increment")
}
Drag options to blanks, or click blank then click option'
A+=
B*=
C-=
D/=
Attempts:
3 left
💡 Hint
Common Mistakes
Using -= decreases the counter instead of increasing it.
Using *= or /= changes the value incorrectly.
3fill in blank
hard

Fix the error in the code to properly save a String state across configuration changes.

Android Kotlin
var name by [1] { mutableStateOf("") }
Drag options to blanks, or click blank then click option'
AmutableStateOf()
Bremember()
CrememberSaveable()
Dstate()
Attempts:
3 left
💡 Hint
Common Mistakes
Using remember() causes the state to reset on rotation.
Using mutableStateOf() alone does not save state across configuration changes.
4fill in blank
hard

Fill both blanks to create a rememberSaveable state for a Boolean flag and toggle it on button click.

Android Kotlin
var isChecked by [1] { mutableStateOf(false) }
Button(onClick = { isChecked = ![2] }) {
    Text("Toggle")
}
Drag options to blanks, or click blank then click option'
ArememberSaveable()
BisChecked
Cremember()
Dflag
Attempts:
3 left
💡 Hint
Common Mistakes
Using remember() instead of rememberSaveable() loses state on rotation.
Negating the wrong variable name causes errors.
5fill in blank
hard

Fill all three blanks to create a rememberSaveable state for a String, update it on text input, and display it.

Android Kotlin
var text by [1] { mutableStateOf("") }
TextField(value = [2], onValueChange = { [3] = it })
Text(text = text)
Drag options to blanks, or click blank then click option'
ArememberSaveable()
Btext
Dremember()
Attempts:
3 left
💡 Hint
Common Mistakes
Using remember() loses state on configuration changes.
Not updating the correct variable on input change.