Android Developer interview question

What triggers recomposition in Jetpack Compose?

Compose recomposes functions that read state when that state changes; stable inputs, correctly scoped state, keys, and derivedStateOf reduce unnecessary work without suppressing required UI updates.

Direct answer

What a strong answer covers

How it works

Compose records which snapshot state objects each composable reads during composition. When one of those objects changes, only the composables that read it, plus any whose inputs are no longer equal, are scheduled to recompose; the rest are skipped. Skipping depends on the compiler being able to prove parameters are stable, which holds for primitives, strings, immutable data classes, and lambdas that capture stable values. Unstable types such as List from a library the compiler cannot analyse force recomposition on every parent recomposition. derivedStateOf collapses frequent changes into fewer downstream updates.

Example

A LazyColumn item that shows a timestamp formatted from a ticking clock recomposes each second, but its sibling rows do not, because only the row reading the clock state is invalidated. A screen that passed an ArrayList of items recomposed the whole list on every keystroke in an unrelated field until the parameter became an ImmutableList and the compiler could skip it.

Common mistakes

  • Reading a state object high in the tree so a tiny change recomposes a whole screen.
  • Creating a new lambda that captures unstable state on every composition and defeating skipping.
  • Using remember without keys for a value that depends on changing inputs and showing stale data.

A useful answer structure

Answer from your own work.

Do not memorise a script: use only examples you can explain honestly in follow-up questions.

Practise this answer with MiraHint

Open the desktop workspace and rehearse a clear answer in your own words.

Download MiraHint
Android Developer interview questions