Challenge - 5 Problems
State Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate2:00remaining
What happens when state changes in a Compose UI?
In Jetpack Compose, when a state variable changes, what is the immediate effect on the UI?
Android Kotlin
var count by remember { mutableStateOf(0) }
Button(onClick = { count++ }) {
Text("Count: $count")
}Attempts:
2 left
💡 Hint
Think about how Compose tracks state and updates UI.
✗ Incorrect
In Jetpack Compose, state variables wrapped with mutableStateOf trigger recomposition when changed, so the UI updates automatically.
🧠 Conceptual
intermediate2:00remaining
Why should UI be driven by state?
Why is it important that UI components reflect the current state rather than storing their own data?
Attempts:
2 left
💡 Hint
Think about what happens when data changes in an app.
✗ Incorrect
When UI reflects state, any change in data automatically updates the UI, keeping the app consistent and easier to maintain.
❓ lifecycle
advanced2:00remaining
What happens if state is not preserved across configuration changes?
In Android, if you store UI state only in a Compose variable without saving it properly, what happens when the device rotates?
Attempts:
2 left
💡 Hint
Consider what happens to activity and Compose state on rotation.
✗ Incorrect
By default, Compose state stored in variables resets on configuration changes like rotation unless saved with rememberSaveable or ViewModel.
📝 Syntax
advanced2:00remaining
Which code correctly updates state to trigger UI change?
Given a Compose state variable 'var text by remember { mutableStateOf("") }', which option correctly updates it on a TextField input?
Android Kotlin
TextField(value = text, onValueChange = { /* update state here */ })Attempts:
2 left
💡 Hint
How do you assign a new value to a state variable in Kotlin?
✗ Incorrect
Assigning the new input string to the state variable triggers recomposition and UI update.
🔧 Debug
expert2:00remaining
Why does this Compose UI not update when state changes?
Consider this code snippet:
var counter = 0
Button(onClick = { counter++ }) {
Text("Clicked $counter times")
}
Why does the UI not show updated count when the button is clicked?
Attempts:
2 left
💡 Hint
Think about how Compose knows when to update UI.
✗ Incorrect
Compose only updates UI when state variables change. A plain variable does not notify Compose of changes.