In short
- Diagnose from the keys and the lifetime before you read the explanation.
- remember keeps a value for its keys. An initialiser is not an ongoing synchronisation contract.
- rememberUpdatedState lets a running effect read the latest callback without restarting.
- A stability annotation is a contract. A false one can hide updates.
- Verify restored UI inputs separately from recovery of pending work, and test the failure path as well as the happy path.
A list reorders and the draft appears on the wrong item. A delayed action invokes an old callback. A screen stops collecting, but its producer keeps running.
Each problem can survive an explanation that merely names remember, LaunchedEffect or StateFlow. The useful interview question asks what those choices preserve, restart or stop in this particular feature.
This page turns that question into 9 exercises. They cover state, composition identity, effects, lifecycle, derived state, stability, restoration and testing. Each one gives a setup, asks for a prediction, gives a reasoned explanation, changes 1 condition and asks you to predict again. The scenes are hypothetical, and they are original practice prompts, not questions attributed to named employers. The answers illustrate defensible reasoning; requirements can justify other designs.
The Compose examples use runtime APIs only and omit UI widgets so their boundaries are easy to inspect. They are not a complete Android screen, and exercise 9 is plain Kotlin with coroutines. Check the project's Kotlin compiler, Compose compiler and runtime versions before treating an optimisation rule as universal.
How each exercise works
Each exercise has the same 4 steps.
- Read the setup and write your prediction in 1 or 2 sentences before you read on.
- Read the explanation and compare it with your prediction.
- Apply the changed condition and predict again.
- Run the check in a small host where you can.
1. Does remember refresh a value when an input changes?
This helper keeps a draft for 1 item.
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.remember
import androidx.compose.runtime.mutableStateOf
@Composable
fun rememberItemDraft(itemId: String, seedTitle: String): MutableState<String> {
return remember(itemId) { mutableStateOf(seedTitle) }
}Predict before reading on. The parent supplies a different seedTitle for the same itemId. Should the draft change?
remember keeps the calculated value for the relevant composition identity and keys. An initialiser is not an ongoing synchronisation contract.[1] The helper resets the draft when the item identity changes, and keeps edits when only the same item's seed title changes.
The omitted seedTitle key is intentional for this draft policy. Adding every input as a key could reset a user's unsaved work on a server refresh. If the parent owns the authoritative editable value instead, hoist that value and its update event rather than maintaining an accidental second copy.
Change 1 condition. The key list becomes itemId and seedTitle, so seedTitle is now a key.
Predict again. A server refresh changes seedTitle while the user has an unsaved edit. What happens to the draft?
Answer. The draft is thrown away and replaced by the new seed, so the user's unsaved edit is lost. A key change makes remember run its calculation again, and mutableStateOf(seedTitle) starts from the seed. Keying on itemId alone keeps the edit.
Then decide the lifetime. Must the draft remain when the user leaves the screen and returns? A remembered value is not a durable application record. A screen owner, saved-state mechanism or persistent draft may be appropriate depending on navigation and recovery requirements.
Check. Edit the draft, change the seed for the same ID, then select a different ID. Describe the expected result after each action before running it.
If you want to repeat this loop with feedback, Guided Practice in Android Interview Training lets you answer realistic prompts, inspect weaknesses, revise your answer and compare attempts.
2. What happens to remembered state when list items move?
Scene. Rows are emitted from a loop, and a new item is inserted at the top.
Predict before reading on. Does the draft stay with its item, and why might in-flight work attach to the wrong item?
Explain composition identity at the call site and how keys distinguish repeated instances. A stable item key lets the framework associate the composition with the intended item when order changes.[2]
For a lazy list, use the list's key mechanism with an identifier valid for the data and state-saving requirements. Replacing an unstable key with a stable one changes identity handling; it does not automatically extend state beyond the lifetime of the relevant composition or restore arbitrary business data.
Change 1 condition. 2 accounts can have the same item ID.
Predict again. Does the draft still follow the right item, and what should reset when the account changes?
Answer. Not safely. If the key is only the item ID, an item from the other account with the same ID can pick up the first account's draft. Decide whether the account change resets the list owner or forms part of its identity. A key that is unique within a single account can still be ambiguous across a surviving account switch.
Check. Insert, reorder and remove items while a row holds a local draft. Observe whether the draft follows the item and whether removal ends its associated work.
3. Why didn't changing a MutableList update the UI?
Scene. An ordinary mutable list is kept inside remembered state. Code changes the list in place, but the display does not reflect the mutation.
Predict before reading on. Does the display update, and why or why not?
Answer. No. Distinguish the state holder from the data it references. An arbitrary collection mutation is not automatically a snapshot-observable state change. Choose an observable collection or publish a new state value with the intended semantics.[1]
Also inspect equality. Reassigning an already-mutated object or an equal value may not provide the change signal you expected. A Kotlin read-only List interface alone does not prove that its backing storage cannot change elsewhere.
Change 1 condition. A colleague proposes adding @Immutable to the class that holds the list.
Predict again. Does the annotation make the display update, and what promise does it make?
Answer. No, and it makes a promise the class may not keep. An annotation does not turn a mutable object graph into an immutable one. It expresses a contract the implementation must satisfy.[3] A false promise can make the framework's optimisation decisions inconsistent with the actual data behaviour.
Check. State which mutation is observable and which object owns it. Verify a payload update for an existing item, not only insertion of a new ID.
4. How do you update a callback without restarting the operation?
Setup. A delayed action belongs to 1 article session. The callback supplied by the parent changes, but the delay should continue.
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.rememberUpdatedState
import kotlinx.coroutines.delay
@Composable
fun DeferredArticleAction(
articleId: String,
delayMillis: Long,
onAction: (String) -> Unit
) {
val currentAction by rememberUpdatedState(onAction)
LaunchedEffect(articleId, delayMillis) {
delay(delayMillis)
currentAction(articleId)
}
}Predict before reading on. The parent replaces onAction halfway through the delay. Does the delay restart, and which callback runs at the end?
Separate the operation's identity from the changing value it should use when it completes. rememberUpdatedState lets a continuing operation read the latest supplied value without making that value a restart key.[4]
Answer. The delay does not restart, and the latest callback runs at the end. Here, article identity and delay policy restart the effect. Callback replacement alone does not. The effect is still scoped to its composition lifetime. This is a UI timing example, not a mechanism for guaranteed background execution.
Change 1 condition. The articleId changes halfway through the delay.
Predict again. Does the effect restart, and what happens to the old article's action?
Answer. Yes, it restarts. The old coroutine is cancelled while it is still delaying, so the old article's action never runs. The new effect starts a full delay for the new article.
Should every captured value use rememberUpdatedState? No. If changing a value should invalidate the operation itself, it belongs in the restart decision. Keeping a request alive while silently changing the meaning of its inputs can be wrong. Write down the desired behaviour for each changing input.
Check. Replace the callback halfway through the delay. Then change the article ID. Those actions should have different effects under this contract.
5. Does lifecycle-aware collection stop all upstream work?
Scene. A screen collects a StateFlow using collectAsStateWithLifecycle. When the screen becomes inactive, is the socket or database producer necessarily stopped too?
Predict before reading on. Does the producer stop when the screen becomes inactive?
Answer. Not necessarily. The collection API manages the UI collection against the lifecycle.[5] Whether production stops depends on the upstream's ownership and sharing policy. A producer owned by a longer-lived scope can remain active even when this collector stops.
Explain both boundaries. One protects screen consumption; the other determines resource lifetime. If the upstream uses a subscription-based policy, define its timeout and what happens with another active subscriber.
Change 1 condition. The screen must display an important result that arrived while it was inactive.
Predict again. Is that outcome current state, a transient signal or durable work?
Answer. Model it as current state held by an owner that outlives the screen, so the screen reads it when it becomes active again. A transient signal sent while nobody collects can be lost, and durable work needs persistence. An event delivery mechanism does not automatically establish safe processing across process death or repeated collection.
Check. Remove the UI collector and observe the actual upstream. Then add a second collector. Do not infer resource behaviour from the screen's visibility alone.
For the coroutine and Flow details, read Kotlin coroutines interview questions.
6. When is calculated state useful, and what does it cost?
Scene. A list changes frequently, but the UI only needs to know whether it is empty. This helper represents that projection.
import androidx.compose.runtime.Composable
import androidx.compose.runtime.State
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.structuralEqualityPolicy
@Composable
fun rememberHasItems(items: State<List<String>>): State<Boolean> {
return remember(items) {
derivedStateOf(structuralEqualityPolicy()) {
items.value.isNotEmpty()
}
}
}Predict before reading on. The list changes from a non-empty list to another non-empty list. Which output changes?
Answer. None. The calculation reruns because it read items.value, but it returns true again. With structuralEqualityPolicy() the result is equal, so readers of the derived state are not invalidated. The derivedStateOf overload without a policy triggers updates on every dependency change, so it would not filter anything here.[6] This does not prevent recomposition caused by other inputs read at the same call site.
Do not wrap every string concatenation or arithmetic expression in calculated state. Dependency tracking and caching have overhead. The reference says that for a trivial calculation the caching can cost more than recomputing, and it points to computedStateOf, added in runtime 1.13.0, which skips the cache but still invalidates readers only when the result changes.[6] isNotEmpty() is that cheap, so in a project on a recent runtime the choice between the 2 is itself a fair follow-up. Check your runtime version before adopting either.
Change 1 condition. The key changes from items to items.value.
Predict again. Does the derived state still protect the caller from list changes?
Answer. No. remember(items.value) reads the state during composition, so the composable that calls the helper recomposes on every list change. That is exactly the cost derivedStateOf is there to avoid. Each new list also creates a new derived state and discards the old one, so neither the caching nor the filtering survives. Key the remembered calculation by the holder and read the value inside the calculation, as the helper above does.
Check. Change a non-empty list to another non-empty list, then to an empty list. Identify which output changes and which unrelated inputs might still invalidate a consumer.
7. Does an unstable parameter always make a composable unskippable?
Scene. A candidate says that any unstable parameter prevents skipping. Is that a safe rule for the current project?
Predict before reading on. Is that rule safe for this project, and what decides whether the composable can be skipped?
Answer. No. Check the compiler configuration. Strong skipping changes skippability and comparison behaviour for restartable composables, and is enabled by default from Kotlin 2.0.20 according to Android's guidance.[7]
Explain the relevant equality or identity assumptions instead of repeating a rule from an older compiler mode. Also distinguish a compiler's ability to skip a call from the work the application performs during the affected user journey.
Change 1 condition. A colleague proposes adding Stable or Immutable to the parameter type as a performance fix.
Predict again. What does that annotation promise, and what must be true for it to help?
Answer. It promises that the type's public state either never changes or notifies Compose when it does. It helps only when that is true. Inspect public behaviour and mutation notification, then measure the actual cost. Incorrect annotations can conceal updates, and a better skip count alone does not establish a smoother screen.[3]
Check. Record the compiler settings and inspect reports or traces relevant to the suspected problem. Keep device, build and content conditions comparable.
8. What state should survive recreation or process death?
Scene. A Compose screen holds a filter, a selected item and an unsent account change.
@Composable
fun FilterPanel() {
var filter by rememberSaveable { mutableStateOf("all") }
var selectedId by rememberSaveable { mutableStateOf<String?>(null) }
// The unsent account change does not belong here.
// It needs storage that survives process death.
}Predict before reading on. Can rememberSaveable own all 3?
Answer. No. The filter and the selected ID are small UI state, and rememberSaveable can restore them after recreation or process death.[8] The unsent account change is user intent. Choose storage by meaning and required lifetime. Appropriate saved-state mechanisms can help reconstruct UI state. Durable user intent belongs in a persistence design that survives the failures the product promises to handle.[8]
Store enough information to rebuild a screen without trying to serialise an entire application graph. Define when state is deliberately discarded, including explicit screen dismissal and account changes.
Change 1 condition. A background request has already reached the server when the process dies.
Predict again. Does restoring the screen show whether the server applied the change?
Answer. No. Restoring the UI does not settle the remote outcome. Reconcile the operation with its stable identity and server contract. A saved Boolean saying "loading" cannot determine whether the server applied the change.
Check. Verify restoration of UI inputs separately from recovery of pending work. Rotation alone is not a complete process-death test.
9. How do you test the logic behind a screen?
Scene. A screen's draft logic lives in a state holder, so it can be tested without rendering anything. The holder takes its scope and its save function from outside.
data class DraftState(
val title: String = "",
val saving: Boolean = false,
val saved: Boolean = false
)
class DraftHolder(
private val scope: CoroutineScope,
private val save: suspend (String) -> Unit
) {
private val _state = MutableStateFlow(DraftState())
val state: StateFlow<DraftState> = _state.asStateFlow()
fun onTitleChanged(title: String) {
_state.update { it.copy(title = title, saved = false) }
}
fun onSave() {
scope.launch {
_state.update { it.copy(saving = true) }
save(_state.value.title)
_state.update { it.copy(saving = false, saved = true) }
}
}
}This test uses a fake save and the test scope.
class DraftHolderTest {
@Test
fun saveMarksTheDraftAsSaved() = runTest {
val saved = mutableListOf<String>()
val holder = DraftHolder(this) { saved += it }
holder.onTitleChanged("Offline sync")
holder.onSave()
assertFalse(holder.state.value.saved)
runCurrent()
assertTrue(holder.state.value.saved)
assertEquals(listOf("Offline sync"), saved)
}
}Predict before reading on. onSave() has just been called and the fake save returns at once. What does saved hold before runCurrent()?
Answer. false. The test scope schedules coroutines on a test scheduler, so the launched coroutine waits until the test lets it run, here with runCurrent().[10] Controlling when work runs is the reason to inject the scope.
Change 1 condition. The save function throws an IOException.
Predict again. What does the state show, and what does the test report?
Answer. The state stays at saving = true and saved = false, and the exception escapes the launched coroutine, so the test fails with the IOException. In the app the same exception would reach the scope's exception handler and could crash the app. The test exposed a missing state, which is the failure. Add it, and rethrow cancellation so the catch does not swallow it.
fun onSave() {
scope.launch {
_state.update { it.copy(saving = true, error = null) }
try {
save(_state.value.title)
_state.update { it.copy(saving = false, saved = true) }
} catch (e: CancellationException) {
throw e
} catch (e: Exception) {
_state.update { it.copy(saving = false, error = "Could not save") }
}
}
}This version assumes DraftState gains val error: String? = null. The new test asserts that saved is false, saving is false and error is set. For why the cancellation line matters, read Kotlin runCatching and cancellation.
A state holder test cannot tell you what is on screen. When the question is rendered output, such as a visible error message after a click, use a Compose UI test with createComposeRule.[11]
Check. Write the failure test before you change the holder and watch it fail. Then add the error state and watch it pass. A test you have never seen fail has not shown that it can.
Explain the phase before proposing the optimisation
If a case turns into a performance discussion, identify whether the work occurs in composition, measurement, placement, drawing or a separate asynchronous operation. Then connect your proposed change to the observed cost.[9]
For example, reducing a recomposition count will not necessarily fix expensive image decoding or a blocked dependency. Keep the correctness contract while investigating the performance issue.
In a practice session, I would ask for a prediction, the relevant ownership rule and a check that could disprove it.
Continue with a focused Android practice route
Choose the 2 exercises that exposed uncertainty and run them in a small host project. Keep the first prediction and the observed result. Repeat after changing an identity, lifecycle boundary or input.
The full question list is in Jetpack Compose interview questions. To see why the follow-up is where the round is decided, read the follow-up decides the senior mobile interview.
For structured preparation, Android Interview Training is $99, paid once. You keep the book and companion code, and you get 90 days of Guided Practice, where you answer realistic prompts, inspect weaknesses, revise your answer, handle changed constraints and compare attempts. It is structured practice, not live coaching with a person. You can read the free sample before buying.
Sources
- Android, State and Jetpack Compose.
- Android, Lifecycle of composables.
- Android, Fix stability issues.
- Android, rememberUpdatedState API.
- Android, collectAsStateWithLifecycle API.
- Android, Compose runtime APIs.
- Android, Strong skipping.
- Android, Save UI state in Compose.
- Android, Compose performance best practices.
- Android, Testing Kotlin coroutines on Android.
- Android, Testing your Compose layout.
Questions readers ask
© 2026 Mike Salari, Interview Runtime. All rights reserved. Quoting a short excerpt with a link to this page is welcome; republishing the article, in full or in part, is not.



