Interview guides / android
Kotlin Interview Questions for Android Engineers
Kotlin interview questions covering coroutines, flows, sealed classes, null safety, and Android usage with example answers.
Kotlin interview questions for Android usually mix language features with real app architecture: coroutines, Flow, sealed UI state, and null safety.
Answer with both language rules and where you use them in ViewModels and repositories.
1.What causes ANRs, and how do you diagnose them?
ANRs happen when the main thread is blocked (~5s for input). Avoid disk/network on Main; use coroutines. Diagnose with ANR traces, StrictMode, and Systrace/Perfetto. Mention BroadcastReceiver and Service timeouts too.
2.What are Entity, DAO, and Database in Room?
Entity=table, DAO=queries, Database=holder. Use suspend/Flow queries; type converters carefully; migrations mandatory for schema changes.
3.What belongs in a ViewModel vs UI layer?
UI state and business orchestration surviving rotation. No Android framework Views, no Context leaks (use Application context carefully). Expose immutable UI state flows.
4.Why prefer DataStore over SharedPreferences?
Async, consistent, Coroutines/Flow API, less ANR risk from main-thread prefs. Use Preferences or Proto DataStore.
5.Why are data classes useful for UI state?
copy(), equals/hashCode, destructuring for immutable state updates. Prefer val properties; avoid mutable lists inside without care.
6.How do Dispatchers.Main, IO, and Default differ? How do you structure structured concurrency in a ViewModel?
Main for UI, IO for blocking I/O, Default for CPU work. viewModelScope cancels on clear. Prefer withContext for thread switches, supervisorScope when children should fail independently, and never leak GlobalScope. Expose UI state via StateFlow.
7.Why collect flows with repeatOnLifecycle?
Stops collection when UI not STARTED/RESUMED, preventing leaks and wasted work. Preferred over lifecycleScope.launchWhenStarted patterns.
8.When StateFlow vs SharedFlow?
StateFlow holds latest value (state). SharedFlow is event stream (one-off effects) with replay/buffer config. Don’t use StateFlow for transient events.
9.Compare Flow and LiveData for UI observation.
Flow is colder/flexible (operators, multiplatform). LiveData is lifecycle-aware out of the box. Prefer StateFlow + repeatOnLifecycle; LiveData still fine in legacy.
10.How do sealed classes model screen state?
Loading/Success/Error exhaustive when branches. Prevents illegal combinations of flags. Pair with StateFlow for clear reducers.
11.Explain unidirectional data flow on Android.
Events in → reduce state → render. Single source of truth StateFlow/Compose state. Side effects (nav, toasts) handled explicitly to avoid duplicating on recomposition.
12.RemoteMediator vs PagingSource roles?
PagingSource loads pages from one source. RemoteMediator coordinates network+DB for layered offline cache. UI collects Flow<PagingData>.
13.Common Android leak sources?
Context in singletons, static Views, inner classes holding Activity, listeners not removed, coroutines without scope. Use LeakCanary.
14.Compare LaunchedEffect, DisposableEffect, SideEffect.
LaunchedEffect: coroutine tied to key. DisposableEffect: setup/cleanup for non-coroutine resources. SideEffect: publish composition to non-Compose world each successful compose. Don’t block composition.
Keep going with AceMobileInterview
Reading helps. Timed practice locks it in. Jump into the interactive track for algorithms with LeetCode links, studio projects, debugging zips, and mobile system design.