Challenge - 5 Problems
Compose Interop Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate2:00remaining
What is the output of this Compose interop code?
Consider this Compose code embedding a traditional Android Button inside Compose. What will the user see and experience?
Android Kotlin
setContent {
AndroidView(factory = { context ->
Button(context).apply {
text = "Click me"
setOnClickListener { Toast.makeText(context, "Clicked!", Toast.LENGTH_SHORT).show() }
}
})
}Attempts:
2 left
💡 Hint
AndroidView lets you embed classic Android Views inside Compose UI.
✗ Incorrect
AndroidView creates and displays the native Android Button inside Compose. The button shows the text and responds to clicks by showing a toast.
❓ lifecycle
intermediate2:00remaining
What happens to the Android View lifecycle inside AndroidView in Compose?
When you use AndroidView in Compose to embed a View, which lifecycle event is guaranteed to be called when the Compose composable leaves the composition?
Attempts:
2 left
💡 Hint
AndroidView manages the View lifecycle according to Compose's composition lifecycle.
✗ Incorrect
When AndroidView leaves composition, the embedded View is removed from the view hierarchy, triggering onDetachedFromWindow().
📝 Syntax
advanced2:00remaining
Which code snippet correctly updates the Android View inside AndroidView when Compose state changes?
You want to update the text of an Android TextView inside AndroidView when a Compose state variable changes. Which snippet correctly does this?
Android Kotlin
var text by remember { mutableStateOf("Hello") }
AndroidView(factory = { context -> TextView(context) }, update = { it.text = text })Attempts:
2 left
💡 Hint
Use the update parameter to react to Compose state changes.
✗ Incorrect
The update lambda runs every recomposition and updates the View with the current Compose state value.
🔧 Debug
advanced2:00remaining
Why does this AndroidView code cause a memory leak?
This code embeds a WebView inside Compose using AndroidView. Why might it cause a memory leak?
AndroidView(factory = { context -> WebView(context) })
Attempts:
2 left
💡 Hint
WebView needs explicit cleanup to avoid leaks.
✗ Incorrect
WebView holds internal resources and references to the context. Without explicit cleanup (like calling destroy()), it can leak memory when Compose removes the AndroidView.
🧠 Conceptual
expert2:00remaining
What is the main benefit of using Compose with existing Views via AndroidView?
Why would a developer choose to embed existing Android Views inside Compose using AndroidView instead of rewriting the UI fully in Compose?
Attempts:
2 left
💡 Hint
Think about migration and reuse of legacy code.
✗ Incorrect
AndroidView allows embedding existing Views so developers can reuse legacy UI or third-party Views while gradually adopting Compose.