skip to content

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 pageshow

explore

questions

page 2 of 2

In a Compose UI test, when do you need waitUntil instead of the rule's automatic idling, and how does it differ from mainClock.advanceTimeUntil?

level: middleimportance: should knowfreq 48%

basics

~20 s

Use 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.

open as a page

In Jetpack Compose, what belongs in AndroidView's factory block versus its update block, and how does AndroidViewBinding apply this to an XML layout?

level: middleimportance: should knowfreq 50%

basics

~20 s

Create 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.

open as a page

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?

level: seniorimportance: should knowfreq 40%

basics

~20 s

Animatable 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.

open as a page

In Compose, a bouquet card should grow into its detail screen through SharedTransitionLayout but only fades; why does the shared element not match, and how do you fix it?

level: seniorimportance: should knowfreq 32%

basics

~20 s

A shared element animates only when two Modifier.sharedElement calls inside one SharedTransitionLayout use equal keys and each gets the AnimatedVisibilityScope of the AnimatedContent or AnimatedVisibility that swaps them. Without a match, each side just fades.

open as a page

In Jetpack Compose, when you expose a custom spacing scale or brand colors through a CompositionLocal, how do you choose compositionLocalOf or staticCompositionLocalOf?

level: seniorimportance: should knowfreq 40%

basics

~20 s

compositionLocalOf 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.

open as a page

In Jetpack Compose, how do you write a custom Layout with its MeasurePolicy, and what stops it from measuring a child twice?

level: seniorimportance: should knowfreq 30%

basics

~20 s

Call 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.

open as a page

In Jetpack Compose, a profile header passes scrollState.value into Modifier.offset(y = ...) and recomposes every scroll frame; how do lambda modifiers fix it?

level: seniorimportance: should knowfreq 42%

basics

~20 s

Compose 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.

open as a page

In Navigation 3, after adding rememberViewModelStoreNavEntryDecorator to NavDisplay, the tank gallery forgets its scroll position and search text whenever the user returns from a tank; why, and what is the fix?

level: seniorimportance: should knowfreq 35%

basics

~10 s

Passing entryDecorators replaces NavDisplay's default list, which held rememberSaveableStateHolderNavEntryDecorator, so entries lose their rememberSaveable state when they leave the screen. List the saveable decorator again, first, then the ViewModel decorator.

open as a page

In Navigation 3, how do SceneStrategy and Scene show a tank gallery and tank detail side by side on tablets, and a feeding-times entry as a dialog?

level: seniorimportance: should knowfreq 30%

basics

~20 s

NavDisplay tries each SceneStrategy in sceneStrategies in order and renders the first Scene returned. A custom strategy returns a two-pane Scene on wide windows when metadata marks gallery and detail; DialogSceneStrategy, listed first, shows dialog-marked entries in a Dialog.

open as a page

In a Navigation Compose shopping app with bottom tabs, how do popUpTo with saveState, launchSingleTop and restoreState keep the cart tab's back stack when users switch tabs?

level: seniorimportance: should knowfreq 55%

basics

~20 s

On each tab tap, navigate with popUpTo(the graph's start destination) { saveState = true }, launchSingleTop = true and restoreState = true. Leaving the cart pops and saves its stack; returning restores Cart and Checkout with their saved state.

open as a page

In Jetpack Compose, when do you use produceState and when snapshotFlow, and what surprises does each one hold?

level: seniorimportance: should knowfreq 40%

basics

~20 s

produceState 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.

open as a page

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?

level: seniorimportance: should knowfreq 55%

basics

~20 s

The 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.

open as a page

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?

level: seniorimportance: should knowfreq 55%

basics

~20 s

Use 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.

open as a page

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?

level: seniorimportance: should knowfreq 34%

basics

~20 s

Behaviour 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.

open as a page

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?

level: seniorimportance: should knowfreq 38%

basics

~20 s

The 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.

open as a page

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?

level: seniorimportance: should knowfreq 30%

basics

~20 s

Without 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.

open as a page

In an Android View screen, a Compose LazyColumn inside a CoordinatorLayout scrolls but never collapses the toolbar; why, and how does rememberNestedScrollInteropConnection fix it?

level: seniorimportance: should knowfreq 35%

basics

~10 s

The 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.

open as a page

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?

level: principalimportance: should knowfreq 30%

basics

~20 s

Rely 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.

open as a page

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?

level: principalimportance: should knowfreq 30%

basics

~20 s

Usually 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.

open as a page

Should an Android lead move an aquarium app to Navigation 3 now, off its Navigation Compose NavHost graph, and what decides it?

level: principalimportance: should knowfreq 28%

basics

~20 s

Migrate when the app needs what Navigation 3 adds, an app-owned stack and scenes for tablets, and fits the official guide: Compose-only destinations, one nesting level, navigation tests. Fragment destinations, deeper graphs or process-death-safe results argue for waiting.

open as a page

In a multi-module Android app on Navigation Compose, would you keep one NavHost with a nested graph per feature module and type-safe routes as the module contract?

level: principalimportance: should knowfreq 30%

basics

~20 s

Usually yes: one NavHost in the app module, a nested graph per feature contributed through a NavGraphBuilder extension, and @Serializable routes in small shared modules. The price is contract modules and app-level wiring; extra NavHosts split the back stack.

open as a page

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?

level: principalimportance: should knowfreq 40%

basics

~20 s

Keep 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.

open as a page

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?

level: principalimportance: should knowfreq 45%

basics

~20 s

Build 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.

open as a page

In Jetpack Compose, what does SideEffect guarantee that code in a composable body does not, and what did 1.12's keyed overload add?

level: middleimportance: nice to knowfreq 30%

basics

~20 s

SideEffect 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.

open as a page

In Jetpack Compose, why write a custom modifier with Modifier.Node and ModifierNodeElement rather than Modifier.composed or a @Composable modifier factory?

level: seniorimportance: nice to knowfreq 22%

basics

~20 s

Modifier.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.

open as a page

In Navigation 3, a tank-detail entry slides in through NavDisplay.TransitionKey metadata, yet a predictive back swipe still fades and scales it; why, and which transition wins?

level: seniorimportance: nice to knowfreq 22%

basics

~20 s

NavDisplay keeps three separate transitions: forward, pop and predictive pop. The entry set only TransitionKey, so a predictive back swipe falls back to NavDisplay's predictivePopTransitionSpec, whose Android default fades in and scales the old content to 0.7; set PredictivePopTransitionKey too.

open as a page

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?

level: seniorimportance: nice to knowfreq 28%

basics

~20 s

Set 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.

open as a page

showing 31–58 of 58