Jetpack Compose Questions with Answers

25 practice questions on Jetpack Compose (Android (Kotlin & Compose)) with answers and step-by-step solutions. Try 10 samples below, then practise all 25 free in the AptiNest app.

Sample questions

Question 1Easy

Which layout places children vertically?

  1. Box
  2. Row
  3. Spacer
  4. Column

Answer: D. Column

Explanation

Row places horizontally; Box stacks children on top of each other.

Step-by-step solution

  1. Column arranges children vertically.
  2. Row arranges them horizontally.
  3. Box stacks them on top of each other.

Why the other options are wrong

  • A. Box stacks children in layers.
  • B. Row places children side by side.
  • C. Spacer only adds empty space.

Question 2Easy

Which composable displays text?

  1. TextView
  2. Label
  3. Text
  4. Span

Answer: C. Text

Explanation

Text("Hello") draws a string; TextView belongs to the old View system.

Step-by-step solution

  1. Compose UI is built from composable functions.
  2. Text("Hello") shows text.
  3. TextView is the older View-system widget.

Why the other options are wrong

  • A. TextView belongs to the XML View system, not Compose.
  • B. Label is not a Compose composable.
  • D. Span is an HTML tag.

Tip: Compose names drop 'View': TextView -> Text.

Question 3Easy

Which composable is clickable and runs code in its onClick lambda?

  1. Divider
  2. Button
  3. Column
  4. Spacer

Answer: B. Button

Explanation

Button(onClick = { ... }) { Text("OK") }.

Step-by-step solution

  1. Button(onClick = { ... }) { Text("OK") } runs the lambda on tap.
  2. Divider, Column and Spacer are layout or decoration composables.
  3. They do not have an onClick parameter.

Why the other options are wrong

  • A. Divider just draws a line.
  • C. Column arranges children vertically; it is not clickable by itself.
  • D. Spacer only adds empty space.

Tip: Tap action = onClick lambda.

Question 4Easy

Recomposition in Compose means:

  1. Restarting the Activity
  2. Reinstalling the app
  3. Re-running on state change
  4. Recompiling the app

Answer: C. Re-running on state change

Explanation

Compose re-invokes affected composables to update the UI.

Step-by-step solution

  1. Compose remembers which state each composable reads.
  2. When that state changes, Compose re-runs those composables.
  3. It updates only what changed.

Why the other options are wrong

  • A. The Activity is not restarted.
  • B. Nothing is reinstalled.
  • D. Nothing is recompiled; it happens at runtime.

Question 5Medium

A TextField in Compose shows typed characters only if:

  1. You use a ViewModel
  2. Its state is updated
  3. It is inside a LazyColumn
  4. You call invalidate()

Answer: B. Its state is updated

Explanation

TextField is controlled: it displays value, and you must update that state in onValueChange.

Step-by-step solution

  1. TextField shows whatever value it is given.
  2. Typing calls onValueChange with the new text.
  3. If the state is not updated, the old value is shown again.

Why the other options are wrong

  • A. Local state works too.
  • C. Containers do not matter.
  • D. Compose has no invalidate().

Question 6Medium

Why is remember { mutableStateOf(0) } used instead of just mutableStateOf(0) inside a composable?

  1. To save it to disk
  2. To survive recomposition
  3. To make the value a constant
  4. To run it on a background thread

Answer: B. To survive recomposition

Explanation

Without remember, a new state object would be created each time the composable re-runs, resetting the value.

Step-by-step solution

  1. A composable body runs again on every recomposition.
  2. Without remember, mutableStateOf(0) would create a new 0 each time.
  3. remember keeps the same state object across recompositions.

Why the other options are wrong

  • A. remember holds memory only, not disk.
  • C. The value can still change.
  • D. Threading is unrelated.

Question 7Medium

In a Column, which parameter controls vertical spacing of children such as Arrangement.spacedBy(8.dp)?

  1. contentAlignment
  2. modifier.weight
  3. verticalArrangement
  4. horizontalAlignment

Answer: C. verticalArrangement

Explanation

Arrangement works along the main axis; Alignment along the cross axis.

Step-by-step solution

  1. In a Column, the main axis is vertical.
  2. verticalArrangement controls main-axis spacing.
  3. Arrangement.spacedBy(8.dp) puts 8 dp between children.

Why the other options are wrong

  • A. contentAlignment belongs to Box.
  • B. weight shares leftover space.
  • D. horizontalAlignment controls the cross axis.

Question 8Medium

Which annotation shows a composable in Android Studio's design preview?

  1. @Sample
  2. @Display
  3. @Design
  4. @Preview

Answer: D. @Preview

Explanation

@Preview functions render in the IDE without running the app.

Step-by-step solution

  1. @Preview marks a composable for Android Studio's preview pane.
  2. It renders without running the app.
  3. You can set device size, theme and more.

Why the other options are wrong

  • A. @Sample is not a Compose preview annotation.
  • B. @Display does not exist for this.
  • C. @Design does not exist for this.

Question 9Hard

Why should composable functions avoid side effects such as writing to a database directly in their body?

  1. It slows down the compiler
  2. They may re-run unpredictably
  3. Databases are blocked in Compose
  4. Composables cannot call Kotlin code

Answer: B. They may re-run unpredictably

Explanation

Side effects belong in effect handlers (LaunchedEffect etc.) or in the ViewModel.

Step-by-step solution

  1. Compose may re-run a composable often and in any order.
  2. It may also skip or cancel compositions.
  3. Side effects in the body could run many times or at the wrong moment.

Why the other options are wrong

  • A. Compile speed is unrelated.
  • C. Databases are not blocked.
  • D. Composables can call normal Kotlin code.

Question 10Hard

Two modifiers are applied: Modifier.padding(16.dp).background(Color.Red) versus Modifier.background(Color.Red).padding(16.dp). What differs?

  1. Nothing; order never matters
  2. The first throws an exception
  3. The second has no padding
  4. Where the padding sits

Answer: D. Where the padding sits

Explanation

Modifiers apply in order; padding before background shrinks the area that gets painted.

Step-by-step solution

  1. Modifiers apply in order, from outside in.
  2. padding then background: the padding sits outside the red area.
  3. background then padding: red fills the padded area too.

Why the other options are wrong

  • A. Modifier order matters.
  • B. Both are valid.
  • C. Both have padding; it just sits in a different place.

Practise all 25 questions free

The full question bank with timed practice, progress tracking and Vidya, your AI tutor. Free, no ads.

Open this topic in the app →

Related topics

See all Android (Kotlin & Compose) topics · All topics