How to use this guide
Try answering each scenario out loud before reading the explanation. Describe your approach, why you chose it, and one trade-off. These questions test your reasoning—not just definitions.
An API request runs again after the screen rotates. What would you do?
Keep screen-related data and loading logic in a ViewModel, rather than the
Activity or Fragment. A ViewModel generally survives configuration changes, so the UI can
observe existing state instead of automatically starting the same work again. Also consider
whether the request is safe to repeat and whether cached data is available. A ViewModel does
not preserve state through process death by itself.
A user leaves the screen while a request is running. Should it continue?
Scope work to its owner. For work owned by a ViewModel, viewModelScope is often
appropriate: its coroutines are cancelled when that ViewModel is cleared. This usually allows
a ViewModel to survive a configuration change while still cancelling its work when the screen
is permanently removed.
Cancellation also depends on the underlying operation supporting it.
Does suspend mean a function runs in the background?
No. The suspend modifier lets a function pause without blocking a thread, but it
does not automatically move work off the caller's dispatcher. For blocking I/O, switch to an
appropriate dispatcher, often inside the repository:
suspend fun loadFromDisk(): Data =
withContext(Dispatchers.IO) {
diskStore.read()
}
The important distinction is between suspending and choosing a thread or dispatcher.
How would you represent loading, success, and failure?
Model the UI state explicitly so the UI can render each outcome. For example, expose a
StateFlow<UiState> and collect it in a lifecycle-aware way. Avoid unrelated
booleans and nullable values if they can represent contradictory states, such as loading and
failed at the same time.
What would you do if an API request fails?
First identify the failure: connectivity, authentication, rate limiting, server error, or an unexpected response. Show a useful message and provide a sensible recovery action. Do not retry every error indefinitely. For transient failures, use a limited retry policy with backoff; for authentication or validation errors, retrying usually will not fix the cause.
How would you support offline use?
A common approach is to store data locally and have the UI read from the local database. A repository can coordinate fetching remote data and updating local storage. The design should also explain how stale data is labelled, how refresh works, and what happens if a network request or local write fails.
How do you preserve state if Android kills the process?
A ViewModel helps with configuration changes but should not be treated as durable storage. Save small, restorable UI values—such as a selected tab or item ID—with an appropriate saved-state mechanism. Store durable app data in a database or other persistent storage. Be clear about which state is temporary UI state and which data must survive an app restart.
What can cause a memory leak in an Activity or Fragment?
A long-lived object retaining an Activity, View, or other short-lived reference can prevent it from being collected. Check callbacks, listeners, and background work that outlive the screen. Use lifecycle-aware collection and remove listeners when their owner is destroyed. When debugging, use memory profiling tools to confirm the suspected reference chain rather than guessing.
Keep preparing
Continue with our Android and Kotlin interview guide, then review the Android coroutines tutorial and Retrofit tutorial.