Jetpack Compose
Composable functions, state-driven recomposition, modifier chains and Material theming in place of XML layouts. Interviewers ask because Compose is now the default for new Android UI.
on this pageshowhide
explore
- Composable Functions6 questions
- State and Recomposition6 questions
- Modifiers & Custom Layouts5 questions
- Animation APIs6 questions
- Side Effects6 questions
- Material Theming5 questions
- Navigation and Lists6 questions
- Navigation 3 & NavDisplay6 questions
- AndroidView & ComposeView6 questions
- Semantics-Based UI Tests6 questions
questions
page 2 of 2In a Compose UI test, when do you need waitUntil instead of the rule's automatic idling, and how does it differ from mainClock.advanceTimeUntil?
basics
~20 sUse waitUntil when the UI waits on work Compose cannot see, such as a background load. It polls a condition until a wall-clock timeout (1,000 ms by default); mainClock.advanceTimeUntil steps the virtual test clock and suits only clock-driven Compose state.
In Jetpack Compose, what belongs in AndroidView's factory block versus its update block, and how does AndroidViewBinding apply this to an XML layout?
basics
~20 sCreate the View and attach its listeners in factory, which runs once per View instance; set state-driven properties in update, which runs after factory and again when state changes. AndroidViewBinding does the same with a generated binding's inflate as the factory.
In Compose, a bouquet card's Animatable settle animation is grabbed mid-flight and the code after animateTo never runs; why, and how should drag, release and settle use the Animatable?
basics
~20 sAnimatable runs one animation at a time: animateTo, animateDecay, snapTo or stop from another coroutine cancels the running one. The cancelled animateTo throws CancellationException, so code after it never runs. Stop on touch, snapTo during drag, animateTo on release.
In Jetpack Compose, when you expose a custom spacing scale or brand colors through a CompositionLocal, how do you choose compositionLocalOf or staticCompositionLocalOf?
basics
~20 scompositionLocalOf tracks reads, so a new value recomposes only readers of current; staticCompositionLocalOf does not, so a change recomposes the provider's whole content. Use static for values that almost never change, such as a spacing scale, and compositionLocalOf for colors that change or animate.
In Jetpack Compose, how do you write a custom Layout with its MeasurePolicy, and what stops it from measuring a child twice?
basics
~20 sCall Layout with a MeasurePolicy that measures each child once, reports its size with layout(width, height) and places the Placeables. Compose throws if a child is measured twice; intrinsic measurements let a parent query sizes first.
In Jetpack Compose, a profile header passes scrollState.value into Modifier.offset(y = ...) and recomposes every scroll frame; how do lambda modifiers fix it?
basics
~20 sCompose reruns work from the phase that read a state. Reading the scroll inside Modifier.offset { } defers it to placement, and graphicsLayer { } or drawBehind { } defer alpha or colour, so scrolling stops recomposing.
In Jetpack Compose, when do you use produceState and when snapshotFlow, and what surprises does each one hold?
basics
~20 sproduceState turns a non-Compose source into Compose State; snapshotFlow turns Compose state reads into a cold Flow. produceState keeps its last value when a key restarts it; snapshotFlow reads in a read-only snapshot and drops equal values.
In Jetpack Compose, a LaunchedEffect(Unit) waits ten seconds and then calls an onCalibrationTimeout parameter, but invokes an outdated lambda; why, and how does rememberUpdatedState fix it?
basics
~20 sThe effect's block captured the lambda from its first composition and never restarts, so later lambdas are ignored. rememberUpdatedState keeps one State updated each recomposition; the effect reads it when the timer fires, getting the latest lambda.
In Jetpack Compose, when should a checkout screen compute a value with `derivedStateOf` instead of `remember` with keys, and when is `derivedStateOf` wasted or wrong?
basics
~20 sUse derivedStateOf when fast-changing state feeds a result that changes rarely, such as a scroll offset that only flips a show-total flag; readers recompose only when the result changes. Use remember with keys when inputs and output change together.
In Compose UI testing, which of a screen's tests can run on Robolectric rather than a device, and why should a captureToImage baseline come from the same environment?
basics
~20 sBehaviour tests run well on Robolectric; system UI such as edge-to-edge or picture-in-picture, and unsupported features like WebView, need a device. captureToImage pixels depend on renderer and density, so compare them only with baselines from the same environment.
After moving a Compose test from the deprecated createComposeRule to the v2 one, why does an assertion right after launching work fail, and how do you fix it?
basics
~20 sThe v2 rule runs composition coroutines on a StandardTestDispatcher, so a launch is queued instead of running eagerly as under the old UnconfinedTestDispatcher. Drain the queue first: waitForIdle or runOnIdle, or mainClock.scheduler.runCurrent() when autoAdvance is off.
In Jetpack Compose, a LazyColumn of AndroidView-hosted lyric views stutters on scroll, and after adding onReset some rows show another song's lyrics; why, and how do you fix both?
basics
~20 sWithout a non-null onReset, AndroidView discards and recreates its View whenever the item leaves, so scrolling inflates constantly. With onReset, Views are reused, and data set in factory goes stale; move per-item data into update.
In an Android View screen, a Compose LazyColumn inside a CoordinatorLayout scrolls but never collapses the toolbar; why, and how does rememberNestedScrollInteropConnection fix it?
basics
~10 sThe LazyColumn's scroll deltas travel only through Compose's nested-scroll chain, so CoordinatorLayout never receives them. Applying Modifier.nestedScroll(rememberNestedScrollInteropConnection()) bridges those deltas to the cooperating View parent, which collapses the toolbar.
As the lead of a multi-module Jetpack Compose codebase, what stability policy would you set: a stability configuration file, annotated models, or relying on strong skipping alone?
basics
~20 sRely on strong skipping plus a rule against re-allocating equal UI models in composition. Keep one shared stability configuration file for types you do not own, and allow @Immutable or @Stable only on small models with cheap equals() where measurement shows churn.
In Jetpack Compose, should a banking app with its own brand palette and spacing scale extend MaterialTheme, replace its subsystems, or build a fully custom design system?
basics
~20 sUsually extend MaterialTheme: brand ColorScheme, Typography and Shapes, plus spacing and semantic colors in custom CompositionLocals, so Material components keep sensible defaults. Replacing subsystems or going fully custom means wrapping or rebuilding every component you use.
As the Android lead on a Jetpack Compose codebase, what rule would you set for where UI state lives: in composables, plain state holder classes or screen-level state holders?
basics
~20 sKeep simple UI element state in the composable that uses it, hoisted only to the lowest common ancestor; put complex UI logic in a remembered plain state holder; keep screen UI state and business logic in a screen-level holder, passing values and lambdas down.
As Android lead of a large View-based app, in what order would you migrate screens to Jetpack Compose, and what rules would you set for the interop seam?
basics
~20 sBuild new screens in Compose first, grow a shared component library, then replace existing screens one at a time, starting with simple ones. Set rules for the seam: one theme, a single state owner, a fixed disposal strategy, and AndroidView only where needed.
In Jetpack Compose, what does SideEffect guarantee that code in a composable body does not, and what did 1.12's keyed overload add?
basics
~20 sSideEffect runs its block after every recomposition that applies successfully, on the apply dispatcher; body code can run for compositions that are discarded. Compose runtime 1.12 added keyed SideEffect overloads that run only when a key changes.
In Jetpack Compose, why write a custom modifier with Modifier.Node and ModifierNodeElement rather than Modifier.composed or a @Composable modifier factory?
basics
~20 sModifier.Node is the API Compose's own modifiers use: a stateless ModifierNodeElement creates or updates a long-lived node, nothing runs in composition, and only the affected phase is invalidated. Composable factories never skip and composed { } is no longer recommended.
In a Compose UI test, how do you use mainClock to check a confirmation banner midway through its enter animation, and why does advanceTimeBy(32) right after the click show no progress?
basics
~20 sSet mainClock.autoAdvance = false, click, then step frames. The first frame recomposes and schedules the animation, the second gives it its start time, so advanceTimeBy(32) leaves it at 0 ms; advance further, then sample the banner.
showing 31–58 of 58