Challenge - 5 Problems
Preview Annotation Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate2:00remaining
What does the @Preview annotation do in Jetpack Compose?
In Android Jetpack Compose, what is the main purpose of the @Preview annotation when used above a composable function?
Attempts:
2 left
💡 Hint
Think about how you can view UI changes quickly without installing the app.
✗ Incorrect
The @Preview annotation lets Android Studio show a live rendering of the composable function's UI in the design view. This helps developers see UI changes instantly.
📝 Syntax
intermediate2:00remaining
Which @Preview annotation usage is correct?
Given these options, which @Preview annotation syntax correctly previews a composable function named Greeting?
Android Kotlin
import androidx.compose.ui.tooling.preview.Preview import androidx.compose.runtime.Composable @Preview @Composable fun Greeting() { // composable content }
Attempts:
2 left
💡 Hint
Remember that composable functions must be marked with @Composable to render UI.
✗ Incorrect
The @Preview annotation must be used on a function marked with @Composable to render the UI preview. Option A correctly combines both annotations.
❓ ui_behavior
advanced2:00remaining
What happens if you omit @Composable but keep @Preview?
Consider this code snippet:
@Preview
fun Sample() {
Text("Hello")
}
What will happen when you try to build or preview this in Android Studio?
Attempts:
2 left
💡 Hint
Think about what annotation is required to use composable UI elements inside a function.
✗ Incorrect
Composable UI elements like Text require the function to be annotated with @Composable. Omitting it causes a build error.
❓ lifecycle
advanced2:00remaining
How does @Preview affect app runtime behavior?
Does the @Preview annotation affect the app's runtime behavior or APK size when the app is installed on a device?
Attempts:
2 left
💡 Hint
Consider if @Preview code runs on the device or only in the IDE.
✗ Incorrect
@Preview is a design-time annotation used by Android Studio. It does not affect runtime or APK size because it is stripped out during compilation.
🧠 Conceptual
expert2:00remaining
Why use multiple @Preview annotations on one composable?
Why would a developer use multiple @Preview annotations with different parameters on the same composable function?
Attempts:
2 left
💡 Hint
Think about how you can see your UI in different themes or screen sizes without changing code.
✗ Incorrect
Multiple @Preview annotations allow developers to see how the UI looks in various conditions like dark mode, font scale, or device sizes.