0
0
Android Kotlinmobile~20 mins

Preview annotation in Android Kotlin - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Preview Annotation Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
ui_behavior
intermediate
2: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?
AIt allows you to see a live preview of the composable UI in Android Studio without running the app.
BIt marks the composable function to be included in the app's release build only.
CIt automatically generates unit tests for the composable function.
DIt disables the composable function from being compiled into the app.
Attempts:
2 left
💡 Hint
Think about how you can view UI changes quickly without installing the app.
📝 Syntax
intermediate
2: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
}
A
@Preview
@Composable
fun Greeting() { /*...*/ }
B
@Preview(showBackground = true)
@Composable
fun Greeting() { /*...*/ }
C
@Preview(showSystemUi = true)
fun Greeting() { /*...*/ }
D
@Preview
fun Greeting() { /*...*/ }
Attempts:
2 left
💡 Hint
Remember that composable functions must be marked with @Composable to render UI.
ui_behavior
advanced
2: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?
AThe preview will show the Text composable correctly.
BThe function will be ignored silently during build and preview.
CThe preview will be empty but the build succeeds.
DThe build will fail with an error because the function is not marked @Composable.
Attempts:
2 left
💡 Hint
Think about what annotation is required to use composable UI elements inside a function.
lifecycle
advanced
2: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?
AYes, it adds extra UI components visible only in debug builds.
BNo, @Preview is only used by Android Studio and is removed from the APK.
CYes, it increases APK size by including preview metadata.
DNo, but it disables the annotated composable at runtime.
Attempts:
2 left
💡 Hint
Consider if @Preview code runs on the device or only in the IDE.
🧠 Conceptual
expert
2: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?
ATo create different versions of the composable for different device architectures.
BTo make the composable function run multiple times at app startup.
CTo generate multiple previews showing the UI in different states or configurations.
DTo automatically generate localization strings for the UI.
Attempts:
2 left
💡 Hint
Think about how you can see your UI in different themes or screen sizes without changing code.