0
0
Android Kotlinmobile~20 mins

rememberSaveable for configuration changes in Android Kotlin - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
rememberSaveable Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
ui_behavior
intermediate
2:00remaining
What happens to the state saved with rememberSaveable on screen rotation?

Consider a Compose UI using rememberSaveable to store a counter value. What will happen to the counter value when the device is rotated (causing a configuration change)?

AThe app crashes because rememberSaveable cannot handle rotation.
BThe counter value resets to its initial value after rotation.
CThe counter value is preserved and restored after rotation.
DThe counter value doubles automatically after rotation.
Attempts:
2 left
💡 Hint

Think about what rememberSaveable is designed to do with state during configuration changes.

📝 Syntax
intermediate
2:00remaining
Which code snippet correctly uses rememberSaveable to save a String state?

Choose the correct Kotlin Compose code that uses rememberSaveable to save a String variable name.

Aval name = remember { mutableStateOf("") }
Bval name = rememberSaveable { mutableStateOf("") }
Cval name = rememberSaveable("")
Dval name = mutableStateOf(rememberSaveable("") )
Attempts:
2 left
💡 Hint

Remember the syntax for using rememberSaveable with mutableStateOf.

lifecycle
advanced
2:00remaining
What is the difference between remember and rememberSaveable regarding process death?

Which statement correctly describes how remember and rememberSaveable behave when the app process is killed by the system?

ANeither <code>remember</code> nor <code>rememberSaveable</code> can restore state after process death.
B<code>remember</code> and <code>rememberSaveable</code> both preserve state after process death automatically.
C<code>rememberSaveable</code> loses state on process death; <code>remember</code> restores it.
D<code>remember</code> loses state on process death; <code>rememberSaveable</code> can restore state if it is Parcelable or can be saved in Bundle.
Attempts:
2 left
💡 Hint

Think about what happens to in-memory state versus saved instance state on process death.

🔧 Debug
advanced
2:00remaining
Why does this rememberSaveable state not restore after rotation?

Given this code snippet, why does the state not restore after device rotation?

var count by rememberSaveable { mutableStateOf(0) }

Button(onClick = { count++ }) {
  Text("Count: $count")
}
ABecause the code uses delegated property <code>by</code> without importing <code>import androidx.compose.runtime.getValue</code> and <code>setValue</code>.
BBecause the variable is declared as <code>var</code> with delegated property, it should be <code>val</code>.
CBecause rememberSaveable requires a key parameter to save the state.
DBecause <code>count</code> is a primitive Int, it cannot be saved by rememberSaveable.
Attempts:
2 left
💡 Hint

Check if the delegated property syntax is fully supported by imports.

🧠 Conceptual
expert
2:00remaining
How does rememberSaveable handle custom data classes for state preservation?

You want to save a custom data class instance using rememberSaveable. Which approach will correctly preserve the state across configuration changes?

AMake the data class implement Parcelable or Serializable and use rememberSaveable normally.
BUse rememberSaveable without changes; all data classes are saved automatically.
CConvert the data class to JSON string manually and save that string with rememberSaveable.
DUse remember instead of rememberSaveable because rememberSaveable does not support custom classes.
Attempts:
2 left
💡 Hint

Think about what types rememberSaveable can save by default.