Android (Kotlin) Interview Questions and Answers
Android and Kotlin interview questions with answers and code: Kotlin language features, coroutines and Flow, Jetpack Compose, lifecycle, ViewModel, architecture, persistence, performance and testing.
Key takeaways
- Android interviews test Kotlin, coroutines, lifecycle and architecture together.
- Jetpack Compose questions (state, recomposition, side effects) are now standard.
- Expect configuration changes and process death questions: where state lives and how it survives.
- Senior roles add modularization, performance, offline-first data and testing strategy.
Contents
Android interviews test Kotlin, coroutines, Compose, lifecycle and architecture, plus how you keep apps fast and reliable. Below are 30 common questions grouped by topic and level, with code.
What Android interviews cover
Editorial estimate.
- Kotlin and coroutines25%
- Jetpack Compose and UI20%
- Lifecycle and architecture20%
- Data, networking and background work15%
- Performance and testing10%
- Coding or take-home10%
Where state should live
| State | Survives recomposition | Survives rotation | Survives process death |
|---|---|---|---|
remember | ✓ | ||
rememberSaveable | ✓ | ✓ | ✓ |
| ViewModel field | ✓ | ✓ | |
SavedStateHandle | ✓ | ✓ | ✓ |
| Room / DataStore | ✓ | ✓ | ✓ |
See also iOS (Swift) and Java interview questions.
Kotlin
1How does Kotlin handle null safety?
JuniorTypes are non-null by default; nullable types are marked with ?. You use safe calls (user?.name), the Elvis operator (name ?: "Guest"), smart casts after null checks, and !! only when you’re certain, since it throws on null.
2val vs var, and what does lateinit do?
Juniorval is read-only after assignment; var can be reassigned. lateinit var allows a non-null property to be initialized later (for example by dependency injection); accessing it before initialization throws an exception.
3What are data classes and sealed classes?
JuniorData classes generate equals, hashCode, toString and copy for value-holding types. Sealed classes and interfaces define a closed set of subtypes, so when expressions can be exhaustive, which is ideal for UI states:
sealed interface UiState {
data object Loading : UiState
data class Success(val items: List<Item>) : UiState
data class Error(val message: String) : UiState
}
4What are scope functions (let, run, apply, also, with)?
MidFunctions that execute a block on an object. apply and also return the object (configuration, side effects); let, run and with return the block’s result. let is common for null checks: user?.let { show(it) }.
5What are extension functions and inline functions?
MidExtension functions add functions to existing types without inheritance (fun String.isEmail(): Boolean). inline functions copy their body and lambda arguments into the call site, avoiding lambda allocations and enabling non-local returns and reified type parameters.
Coroutines and Flow
6What are coroutines, and how do they differ from threads?
MidLightweight, suspendable computations. A suspended coroutine doesn’t block its thread, so thousands can run on a few threads. They make asynchronous code sequential and readable, with structured concurrency for cancellation.
7What is structured concurrency?
MidCoroutines are launched in a scope, and the scope doesn’t complete until its children finish. Cancelling the scope cancels all children, and failures propagate to the parent. On Android, viewModelScope and lifecycleScope tie coroutines to component lifetimes, preventing leaks.
8What are dispatchers?
MidThey decide which threads run a coroutine: Dispatchers.Main for UI, Dispatchers.IO for blocking I/O, Dispatchers.Default for CPU-intensive work. Use withContext(Dispatchers.IO) inside repository functions so callers can stay on Main.
9launch vs async?
Midlaunch starts a coroutine that doesn’t return a result (returns a Job). async returns a Deferred whose result you get with await(), used to run tasks in parallel inside a scope.
10Flow vs StateFlow vs SharedFlow?
MidA cold Flow emits values only when collected. StateFlow is a hot flow that always holds a current value, ideal for UI state. SharedFlow is a hot flow for events broadcast to several collectors, with configurable replay.
11How do you collect flows safely in the UI?
SeniorCollect only while the UI is visible: repeatOnLifecycle(Lifecycle.State.STARTED) in views, or collectAsStateWithLifecycle() in Compose. This stops work in the background and avoids wasted resources.
Get Android (Kotlin) answer points in real time during your interview
Sottena listens to the interviewer, detects each question and shows short answer points in about a second. 150 free credits, no card required.
Jetpack Compose
12What is recomposition?
MidWhen state read by a composable changes, Compose re-runs that composable to update the UI. It can skip composables whose inputs haven’t changed. Composables should therefore be fast and free of side effects.
13remember vs rememberSaveable?
Midremember keeps a value across recompositions but loses it on configuration changes. rememberSaveable also saves it in the instance state bundle, so it survives rotation and process death (for saveable types).
14What is state hoisting?
MidMoving state up to a caller and passing the value and an event callback down, making composables stateless and reusable: SearchBar(query = query, onQueryChange = { query = it }).
15How do side effects work in Compose?
SeniorUse effect APIs instead of running side effects directly in composition: LaunchedEffect(key) runs a coroutine when the key changes, DisposableEffect handles setup and cleanup, rememberCoroutineScope launches work from callbacks, and SideEffect publishes state to non-Compose code.
16How do you improve Compose performance?
SeniorRead state as late as possible (for example in lambdas or Modifier blocks), use stable and immutable types, use key and contentType in lazy lists, avoid heavy work in composition, use derivedStateOf for computed state, and check recomposition counts with the Layout Inspector.
Lifecycle and architecture
17Explain the activity lifecycle.
JunioronCreate → onStart (visible) → onResume (interactive) → onPause → onStop (not visible) → onDestroy. Configuration changes such as rotation destroy and recreate the activity by default, so state must be stored elsewhere.
18Why use a ViewModel?
MidIt survives configuration changes, holds UI state and business logic outside the UI, and exposes state through StateFlow. Its viewModelScope cancels work when the ViewModel is cleared. It does not survive process death; use SavedStateHandle for small essential state.
19How do you handle process death?
MidThe system can kill your app in the background and restore it later with saved state. Persist essential UI state in SavedStateHandle or rememberSaveable, reload data from repositories, and test it with “Don’t keep activities” or by killing the process from the developer tools.
20What is MVVM vs MVI in Android?
MidIn MVVM, the ViewModel exposes observable state and the view binds to it. MVI adds unidirectional data flow: the UI sends intents, a reducer produces a single immutable state, and the UI renders it. Many modern apps use an MVVM structure with a single UI state object, which is close to MVI.
21What does dependency injection with Hilt give you?
MidGenerated, compile-time-checked DI integrated with Android components and lifetimes (@Singleton, @ViewModelScoped), injection into ViewModels with @HiltViewModel, and easy replacement of dependencies in tests.
22How would you modularize a large Android app?
SeniorSplit by feature modules with shared core modules (design system, networking, data), keep dependencies one-directional, expose features through APIs, and use convention plugins for Gradle configuration. Benefits: faster builds, clearer ownership and better encapsulation.
Data and networking
23What is Room, and why use it?
MidAn abstraction over SQLite with compile-time checked queries, entities and DAOs, migrations and Flow support for observing changes. It’s the standard choice for local structured data.
24How do you build an offline-first feature?
SeniorMake the local database the single source of truth: the UI observes it, the repository syncs with the network and writes results to the database. Queue local changes and sync them with WorkManager, handle conflicts, and show sync status in the UI.
25When do you use WorkManager?
MidFor deferrable, guaranteed background work that must run even if the app is closed or the device restarts: uploads, sync, periodic cleanup. It respects constraints like network and battery and works within the system’s background limits.
Performance and testing
26How do you find and fix memory leaks on Android?
MidUse LeakCanary in debug builds and the Android Studio memory profiler. Common causes: long-lived objects holding an Activity or View (static fields, singletons, listeners not removed), and coroutines or callbacks outliving their screen.
27How do you improve app startup time?
MidMeasure with Macrobenchmark, defer non-essential initialization (lazy init, App Startup), avoid heavy work on the main thread, reduce the first screen’s complexity, and add Baseline Profiles so critical code is precompiled.
28How do you test an Android app?
MidUnit tests for ViewModels and use cases with fake repositories and kotlinx-coroutines-test, Compose UI tests with semantics matchers, integration tests for Room with an in-memory database, and a few end-to-end tests for critical flows.
29Write a ViewModel that loads items and exposes UI state.
Mid@HiltViewModel
class ItemsViewModel @Inject constructor(
private val repo: ItemsRepository
) : ViewModel() {
private val _state = MutableStateFlow<UiState>(UiState.Loading)
val state: StateFlow<UiState> = _state.asStateFlow()
init { load() }
fun load() = viewModelScope.launch {
_state.value = UiState.Loading
_state.value = runCatching { repo.items() }
.fold({ UiState.Success(it) }, { UiState.Error(it.message ?: "Error") })
}
}
Note that runCatching also catches CancellationException; in production code, rethrow it.
30How do you secure sensitive data in an Android app?
SeniorKeep secrets on the server, store tokens with the Android Keystore (encrypted storage), use HTTPS with certificate pinning where justified, avoid logging sensitive data, set android:allowBackup appropriately, and obfuscate with R8.
How to prepare
- Master coroutines and FlowScopes, dispatchers, cancellation, StateFlow and lifecycle-aware collection.
- Practice Compose fundamentalsState, recomposition, hoisting and side-effect APIs.
- Explain state survivalConfiguration changes vs process death, and where each piece of state lives.
- Build a small sample appList + detail screen with Room, Retrofit, Hilt and tests.
- Prepare a performance storyA leak, jank or startup problem you fixed, with measurements.
Get answer points in real time during your interview
Sottena listens to the interviewer, detects each question and shows short answer points in about a second. 150 free credits, no card required.