How to approach scenario questions
Interviewers want to hear how you investigate constraints, make trade-offs, and verify a solution. Use each problem to explain a practical decision process, not just name a language feature.
A clear answer structure
- Clarify requirements and failure conditions.
- Explain the approach and why it fits.
- Cover trade-offs, safety, and edge cases.
- Describe how you would test and measure it.
Real-world problem 1
A coroutine continues after the user leaves a screen. How would you fix its scope?
The scenario
A network request launched from a global scope updates a screen that is no longer visible.
A strong answer
Launch screen-related work in a lifecycle-owned scope such as viewModelScope, and let cancellation propagate to child coroutines. Avoid GlobalScope for feature work. Keep durable background work in an appropriate platform-managed worker rather than tying it to a screen.
Real-world problem 2
An Android screen loses important state after process death. What would you persist?
The scenario
Rotation works, but returning to the app after the operating system kills its process resets the current form and selected item.
A strong answer
Keep UI state in a ViewModel across configuration changes and save small restorable values with SavedStateHandle. Persist durable user data in a database or repository. Do not store large or long-lived domain data only in a Bundle.
Real-world problem 3
The app must work offline and sync when connectivity returns. How would you model data flow?
The scenario
The UI currently reads only from the network and becomes empty when a request fails.
A strong answer
Use the local database as the UI source of truth and expose it with Flow. Refresh from the network and persist successful results locally, while tracking pending writes and sync state. Define conflict and retry behavior rather than treating connectivity as guaranteed.
Real-world problem 4
Several callers trigger the same expensive request at once. How can you avoid duplicate work?
The scenario
Multiple screens request the same account data during startup and each launches its own network call.
A strong answer
Move request ownership into a repository or shared data layer and coordinate concurrent callers through a cached in-flight Deferred, Mutex, or a suitable Flow design. Define cache freshness and invalidation explicitly, and clear failed in-flight state so later attempts can retry.
Real-world problem 5
How should a repository retry failed network operations?
The scenario
The current code retries every exception immediately, including invalid requests and authentication failures.
A strong answer
Retry only failures that are transient and operations that are safe to repeat. Use a bounded exponential backoff with jitter, respect cancellation, and handle authentication or validation errors through their own paths. Surface the final failure instead of retrying forever.
Real-world problem 6
A Flow collector causes work or UI updates after the screen is stopped. What should change?
The scenario
A Fragment collects a Flow for its full lifetime even when its view is not visible.
A strong answer
Collect UI flows with a lifecycle-aware pattern such as repeatOnLifecycle, using the view lifecycle when appropriate. This cancels collection below the active state and restarts it when visible again. Keep expensive upstream work shared only when its lifecycle and replay behavior are intentional.
Real-world problem 7
A shared mutable value occasionally becomes inconsistent across coroutines. How do you protect it?
The scenario
Several coroutine workers update a normal mutable collection without coordination.
A strong answer
Prefer a single owner that exposes immutable snapshots through StateFlow, or protect compound updates with Mutex. Confinement to a dispatcher can work when all access follows that rule. A thread-safe collection alone may not make a multi-step business operation atomic.
Real-world problem 8
A list screen drops frames while rendering many items. What would you inspect?
The scenario
Scrolling becomes janky after the screen starts loading a large dataset and remote images.
A strong answer
Profile frame time and trace the main thread before optimizing. Use a lazy list with stable keys, avoid expensive work during composition or binding, load images asynchronously at display size, and move CPU or blocking I/O work off the main dispatcher.