0
0
Android Kotlinmobile~20 mins

Composable functions in Android Kotlin - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Composable Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
ui_behavior
intermediate
2:00remaining
What is the output of this Composable function?
Consider this Kotlin Compose code snippet. What will be displayed on the screen?
Android Kotlin
import androidx.compose.material.Text
import androidx.compose.runtime.Composable

@Composable
fun Greeting() {
  Text(text = "Hello Compose")
}
AA runtime error due to missing setContent call
BA blank screen with no text
CA text label showing 'Hello Compose' on the screen
DA button labeled 'Hello Compose'
Attempts:
2 left
💡 Hint
Look at what the Text composable does inside the Greeting function.
lifecycle
intermediate
2:00remaining
When is a Composable function recomposed?
Given a Composable function with a state parameter, when does Compose re-run the function to update the UI?
AWhen the state parameter value changes
BOnly once when the app starts
CEvery time the user clicks anywhere on the screen
DNever, Composables run only once
Attempts:
2 left
💡 Hint
Think about what triggers UI updates in Compose.
📝 Syntax
advanced
2:00remaining
Which option correctly defines a Composable function with a parameter?
Select the correct Kotlin Compose function syntax that takes a String parameter and displays it.
Afun @Composable ShowMessage(message: String) { Text(message) }
B@Composable fun ShowMessage(message: String) { Text(text = message) }
C@Composable fun ShowMessage(message) { Text(text = message) }
D@Composable fun ShowMessage(message: String) { Text(message = message) }
Attempts:
2 left
💡 Hint
Remember the correct placement of the @Composable annotation and parameter types.
🔧 Debug
advanced
2:00remaining
What error occurs with this Composable code?
Analyze this code snippet and identify the error it causes.
Android Kotlin
import androidx.compose.material.Text
import androidx.compose.runtime.Composable

@Composable
fun MyText() {
  Text("Hello")
}
ACompilation error: Missing @Composable annotation
BRuntime error: NullPointerException
CNo error, displays 'Hello' text
DCompilation error: No value passed for parameter 'text'
Attempts:
2 left
💡 Hint
Check the Text composable parameter requirements.
🧠 Conceptual
expert
2:00remaining
What is the main benefit of using Composable functions in Android development?
Choose the best explanation for why Composable functions are used in modern Android UI development.
AThey allow building UI declaratively and automatically update UI on state changes
BThey replace all XML layouts with imperative code only
CThey guarantee zero memory usage during UI rendering
DThey force UI updates only when the app restarts
Attempts:
2 left
💡 Hint
Think about how Compose handles UI and state.