Android Jetpack Compose Interview Questions

State, layout, navigation, and performance.

50 questions in this topic · 8 sample questions below

Practice Jetpack Compose in the quiz engine

Sample questions

  1. A Composable reads a value from a State object during composition. What guarantees that this Composable recomposes when the value changes?

    • Compose registers the read as a subscription in the current recomposition scope, so a write to that State invalidates only scopes that read it — correct
    • Compose diffs the entire tree on every frame and re-runs any node whose output differs
    • The @Composable annotation makes every function reactive to all State in scope
    • Recomposition is triggered by the setContent block re-executing on state change

    Why: Snapshot state records which recomposition scopes read it, so only those scopes are invalidated on write. There is no per-frame tree diff; reading state is what creates the dependency, not the @Composable annotation.

  2. Which statement about the three Compose phases is correct?

    • Composition, then measurement, then drawing all run for every changed pixel each frame
    • Layout always re-runs whenever composition re-runs, since size depends on content
    • Drawing happens before layout so the GPU can precompute bounds
    • Composition produces the tree; layout measures and places nodes; draw renders them, and a state read can trigger only the phases at or after where it is read — correct

    Why: The phases are composition, layout, draw, and reading state in a later phase (for example via a lambda) can skip earlier phases. Layout does not automatically re-run just because composition did if no layout-affecting state changed.

  3. You animate a scroll offset and apply it with Modifier.offset { IntOffset(0, scroll.roundToInt()) } using the lambda overload instead of Modifier.offset(y = scroll.dp). Why is the lambda version more efficient?

    • The lambda version caches the offset so identical values are skipped
    • The lambda runs on a background thread, freeing the main thread
    • The lambda overload reads the state during the layout phase, so changing the offset skips recomposition and re-runs only layout and draw — correct
    • The lambda version is applied during draw only, skipping both composition and layout

    Why: The lambda overload defers the state read to the layout phase, so an offset change invalidates layout and draw but not composition. The non-lambda version reads state in composition, forcing recomposition each frame.

  4. What does it mean for a Composable to be skippable?

    • It has no side effects, so Compose can drop it from the tree entirely
    • It never recomposes because it holds no state
    • It can be skipped only if it returns Unit and takes no parameters
    • During recomposition Compose can skip re-executing it if all its parameters are stable and unchanged compared to the previous call — correct

    Why: Skippable means Compose can bypass re-execution when every parameter is stable and compares equal to the last call. Having no state is neither necessary nor sufficient; stability of parameters is the criterion.

  5. What is the difference between a restartable and a skippable Composable?

    • They are synonyms produced by the same compiler pass
    • Restartable composables return values; skippable ones do not
    • Restartable means it can be re-invoked independently when invalidated; skippable means that re-invocation can be avoided when inputs are unchanged — correct
    • Skippable is a superset of restartable: every skippable function is restartable but not vice versa

    Why: Restartable means the compiler wrapped the function so it can restart at its own scope; skippable means that restart can be avoided when arguments are equal and stable. A function returning a value is typically neither restartable nor skippable.

  6. A data class has all val properties of stable types but Compose still treats it as unstable, breaking skipping. What is the most likely cause?

    • It is defined in a module the Compose compiler did not process, for example a plain Kotlin library without the Compose plugin, so stability could not be inferred — correct
    • Data classes are always unstable by design
    • val properties are considered mutable by Compose
    • It needs a no-argument constructor to be stable

    Why: The compiler can only infer stability for types it compiles; a class from a non-Compose module is treated as unstable unless annotated. Data classes with stable vals are otherwise inferred stable, and vals are not treated as mutable.

  7. Why does passing a lambda that captures a mutable variable sometimes prevent a child Composable from being skipped?

    • Lambdas are never stable in Compose
    • Lambdas always allocate a new instance, so equality never holds
    • Capturing any variable forces the lambda onto the heap, defeating skipping
    • A lambda that captures unstable values is itself unstable, so the child sees a changed unstable parameter each recomposition — correct

    Why: Compose can memoize lambdas that capture only stable values, keeping them stable across recompositions; capturing an unstable value makes the lambda unstable so the child is not skipped. Lambdas are not inherently unstable, and captured stable values are remembered.

  8. What is the practical effect of annotating a class with @Immutable versus @Stable?

    • @Immutable promises the public properties never change after construction; @Stable promises Compose will be notified via snapshot state whenever an observable property changes — correct
    • @Immutable makes fields final; @Stable makes the class thread-safe
    • They are identical annotations kept for backward compatibility
    • @Stable makes the class skippable; @Immutable makes it restartable

    Why: @Immutable is a stronger contract that values never change after construction; @Stable allows mutation but promises Compose is notified through snapshot state. Neither controls restartability, and they are not equivalent.

Practice all 50 Jetpack Compose questions

These 8 are a sample. The full Jetpack Compose bank is scored, tracks your progress, and explains every answer.

Open the quiz

More Android interview topics