Android Interview Questions & Answers
A comprehensive bank of Android interview questions — from fundamentals to senior topics. Each answer is point-by-point so you can speak it clearly. Practise saying them out loud.
1. What is the difference between an Activity and a Fragment?
- Activity — a full screen and app entry point with its own window; declared in the manifest.
- Fragment — a reusable UI portion hosted inside an Activity; has its own lifecycle but can’t live alone.
- Modern usage — one Activity hosting many fragments via the Navigation Component.
2. Explain the Activity lifecycle.
onCreate(build UI, once) →onStart(visible) →onResume(interactive).onPause(losing focus) →onStop(hidden) →onDestroy(removed).- On rotation the activity is destroyed and recreated — keep state in a ViewModel.
3. Explain the Fragment lifecycle and its key gotcha.
- Key callbacks:
onCreate,onCreateView,onViewCreated(set up the view here),onDestroyView,onDestroy. - The fragment’s view can be destroyed while the fragment lives on.
- Gotcha: null the view binding in
onDestroyViewto avoid leaks.
4. What is Context and what are its types?
- A handle to app resources, system services and components.
- Application context — app-lifetime (singletons, app-wide work).
- Activity context — UI work (dialogs, inflation, themes).
- Never store an Activity context in a long-lived object (leak).
5. What are the four app components?
- Activity — a screen.
- Service — background work, no UI.
- BroadcastReceiver — reacts to system/app events.
- ContentProvider — shares data between apps.
6. What is the AndroidManifest.xml for?
- Declares components, the launcher activity, permissions, and app metadata.
- The system reads it before running the app.
- The MAIN/LAUNCHER intent-filter marks the first screen.
7. What is an Intent? Explicit vs implicit.
- A message to do something (open a screen, share, dial).
- Explicit — names the exact component (your own screen).
- Implicit — describes an action; the system picks an app.
8. How do you pass data between activities/fragments?
- Activities — Intent extras (small data) or an id to reload.
- Fragments — Safe Args (Navigation) or a shared ViewModel.
- Avoid passing large objects; pass an id and fetch.
9. What is a PendingIntent?
- A token that lets another app/system (notifications, alarms) execute an Intent as your app later.
- Must specify mutability flags (
FLAG_IMMUTABLE/FLAG_MUTABLE).
10. What causes an ANR and how do you prevent it?
- The main thread blocked ~5s (input) — from network, DB, parsing, disk on the UI thread.
- Fix: move I/O and heavy work to background coroutines (
Dispatchers.IO). - Detect with StrictMode and Play Console/Crashlytics ANR reports.
11. What is the difference between the main thread and worker threads?
- The main (UI) thread draws the UI and handles input; only it may touch views.
- Worker threads run heavy work; results must be posted back to the main thread.
12. Explain Handler, Looper and MessageQueue.
- The main thread runs a Looper that processes a MessageQueue.
- A Handler posts messages/Runnables onto a thread’s queue.
- It’s how you schedule work onto the main thread (modern code uses coroutines instead).
13. What is a ViewModel and why use it?
- Holds UI state and survives configuration changes (rotation).
- Keeps Activities/Fragments thin; cleared in
onCleared(). - Must never reference a View or Activity Context.
14. SavedStateHandle vs onSaveInstanceState vs ViewModel.
- onSaveInstanceState — small UI state, survives process death (Bundle).
- ViewModel — survives rotation but not process death.
- SavedStateHandle — ViewModel state that also survives process death.
15. LiveData vs StateFlow vs SharedFlow.
- LiveData — lifecycle-aware, simple, framework-bound.
- StateFlow — hot, always has a current value (state).
- SharedFlow — hot, for one-off events (no current value).
16. Explain coroutines and suspend functions.
- Coroutines write async code sequentially;
suspendfunctions pause without blocking the thread. - They run in a scope and use dispatchers to pick a thread.
17. What is structured concurrency?
- Coroutines form a tree under a scope; cancelling/failing the scope cancels children.
- Prevents leaks — e.g.
viewModelScopecancels work when the screen is gone.
18. launch vs async.
launch— fire-and-forget, returns a Job.async— returns a Deferred youawait; use for parallel work.
19. What are coroutine dispatchers?
Main— UI;IO— network/disk;Default— CPU-heavy work.- Switch with
withContext(Dispatchers.IO) { }.
20. What is Flow and how is it different from a suspend function?
- A
suspendfunction returns one value; a Flow emits many over time. - Cold by default (runs on collect); great for DB queries and streams.
21. How does RecyclerView work?
- Recycles off-screen row views instead of creating new ones.
- Uses Adapter + ViewHolder + LayoutManager.
- Use ListAdapter + DiffUtil for animated, efficient updates.
22. What is DiffUtil?
- Computes the minimal set of changes between two lists.
- Animates insert/remove/move instead of
notifyDataSetChanged().
23. ConstraintLayout vs LinearLayout vs RelativeLayout.
- ConstraintLayout — flat, flexible, best for complex screens.
- LinearLayout — simple rows/columns with weights.
- RelativeLayout — older; mostly replaced by ConstraintLayout.
24. View Binding vs Data Binding vs findViewById.
- findViewById — old, error-prone.
- View Binding — type-safe references, no XML expressions.
- Data Binding — binds data/expressions in XML; heavier.
25. dp vs sp vs px.
- dp — density-independent pixels for sizes.
- sp — like dp but scales with the user’s font setting (use for text).
- px — raw pixels; avoid (varies by device).
26. How do resources and qualifiers work?
- Resources live in
res/(strings, colors, drawables, layouts). - Qualifiers (
values-hi,drawable-hdpi,values-night) auto-select by language, density, theme.
27. How do you support dark mode?
- Use a DayNight theme and provide
values-nightcolors. - Read theme attributes (e.g.
?attr/colorSurface) instead of hard-coded colors.
28. What is the difference between a Service, IntentService and WorkManager?
- Service — runs in the background (foreground service for user-visible work).
- IntentService — deprecated; sequential background tasks.
- WorkManager — guaranteed deferrable work, even after restart.
29. When do you use a Foreground Service?
- Long-running, user-aware tasks: music, navigation, active uploads.
- Requires a persistent notification.
30. What is WorkManager good for, and its constraints?
- Guaranteed background work: sync, upload, backup.
- Supports constraints (network, charging) and retries with backoff.
31. What is a BroadcastReceiver?
- Listens for system or app broadcasts (connectivity, boot, custom events).
- Register in the manifest (limited) or at runtime (context-registered).
32. What is a ContentProvider?
- A controlled interface to share structured data across apps (e.g. Contacts).
- Accessed via a content URI and a ContentResolver.
33. Serializable vs Parcelable.
- Serializable — easy but slow (reflection, garbage).
- Parcelable — Android-optimised, fast; use
@Parcelize.
34. How does the Navigation Component work?
- A nav graph (XML) defines destinations and actions.
- One Activity + NavHost hosts fragments; navigate with
findNavController(). - Pass data type-safely with Safe Args.
35. Explain Room and its main parts.
- Google’s SQLite library: Entity (table), DAO (queries), Database.
- Queries can be
suspendor returnFlowfor reactive updates. - Bump version + add a migration when the schema changes.
36. SharedPreferences vs DataStore.
- SharedPreferences — classic key-value, synchronous API.
- DataStore — modern, async (coroutines/Flow), safer; recommended.
37. How do you do networking with Retrofit?
- Describe endpoints in an interface with annotations (
@GET,@POST). - Use a converter (Moshi/Gson) for JSON; functions are
suspend. - Add the INTERNET permission; handle errors.
38. What is OkHttp and an interceptor?
- OkHttp is the HTTP client under Retrofit.
- An interceptor handles cross-cutting concerns: auth headers, logging, token refresh.
39. Explain dependency injection and Hilt.
- DI = objects are provided, not created inside a class (testable, decoupled).
- Hilt annotations (
@HiltAndroidApp,@AndroidEntryPoint,@Inject, modules) generate the wiring.
40. Dagger vs Hilt vs Koin.
- Dagger — powerful, compile-time, verbose.
- Hilt — Dagger made easy for Android.
- Koin — simpler, runtime (service locator-ish), Kotlin-first.
41. Explain the MVVM architecture.
- View displays state and sends events; ViewModel holds state/logic; Model/Repository provides data.
- UI observes the ViewModel; one-way data flow.
42. What is the repository pattern?
- A single source of truth that decides whether data comes from network or DB.
- Hides data sources from the ViewModel; improves testability.
43. What is Clean Architecture on Android?
- Layered: presentation → domain (use cases) → data, dependencies pointing inward.
- Maximises testability; can be overkill for small apps.
44. What are common causes of memory leaks?
- Static fields / singletons holding Activity/View/Context.
- Uncancelled listeners, coroutines, or anonymous inner classes capturing the Activity.
- Detect with LeakCanary and the Memory Profiler.
45. What are launch modes?
- standard (new instance), singleTop (reuse if on top), singleTask (one in task), singleInstance (own task).
- They control duplicates and Back behaviour.
46. How does the back stack work?
- A stack (LIFO) of activities/destinations; Back pops the top.
popUpTo/FLAG_ACTIVITY_CLEAR_TOPcontrol clearing (e.g. login → home).
47. What is the difference between commit() and apply() in SharedPreferences?
- commit() — synchronous, returns success, blocks the thread.
- apply() — asynchronous, no return; preferred to avoid blocking.
48. What is multidex?
- Splits methods across multiple DEX files when an app exceeds the 64K method limit.
- Enabled automatically for minSdk 21+.
49. What are ProGuard / R8?
- R8 shrinks, obfuscates and optimises release code, reducing app size.
- Add keep rules for reflection-based libraries (e.g. Gson models).
50. APK vs AAB (App Bundle).
- APK — the installable file.
- AAB — what you upload; Play generates optimised APKs per device (smaller downloads).
51. What are build variants / product flavors?
- Build types (debug/release) and flavors (free/paid, dev/prod) produce different builds from one codebase.
- Useful for environments and white-labelling.
52. minSdk vs targetSdk vs compileSdk.
- minSdk — oldest supported version.
- targetSdk — version you tested for (keep current for Play).
- compileSdk — SDK you compile against.
53. How do runtime permissions work?
- Dangerous permissions (camera, location) must be requested at runtime, in context.
- Use the Activity Result API; handle denial gracefully.
54. How do notifications and channels work?
- Since Android 8, every notification needs a channel (category users can control).
- Android 13+ needs the POST_NOTIFICATIONS runtime permission.
- Attach a PendingIntent to open a screen.
55. What are deep links and App Links?
- Deep link — a URI that opens a specific screen.
- App Link — a verified HTTPS deep link that opens your app without a chooser.
56. How do you store data securely?
- Tokens/secrets → the Android Keystore / EncryptedSharedPreferences (never plain prefs).
- HTTPS for transit; consider certificate pinning.
57. What is the Activity Result API?
- The modern replacement for
startActivityForResult. - Register a contract (pick image, request permission) and launch it.
58. What is the difference between Bundle and Intent extras?
- A Bundle is a key-value container; Intent extras are stored in a Bundle.
- Used to pass small, serializable/parcelable data between components.
59. How do configuration changes affect the app?
- Rotation/locale/dark-mode changes recreate the Activity by default.
- Keep state in a ViewModel / SavedStateHandle; avoid
android:configChangeshacks.
60. What is the difference between onCreate, onCreateView, and onViewCreated in a Fragment?
- onCreate — non-UI setup.
- onCreateView — inflate and return the view.
- onViewCreated — the view exists; do view setup here.
61. What is a sealed class and why use it for UI state?
- A fixed set of subtypes the compiler knows; each can carry data.
- Model Loading/Success/Error so
whenis exhaustive and safe.
62. What is the difference between == and === in Kotlin?
==— structural equality (callsequals).===— referential equality (same object).
63. What are Kotlin scope functions?
let,run,with,apply,also.apply/alsoreturn the object;let/run/withreturn the last line.
64. How do you handle errors in coroutines?
- Wrap calls in try/catch; catch specific exceptions first.
- Use a
CoroutineExceptionHandleror a SupervisorJob so one failure doesn’t cancel siblings.
65. What is the difference between Flow, StateFlow and SharedFlow?
- Flow — cold stream, runs on collect.
- StateFlow — hot, holds latest value (UI state).
- SharedFlow — hot, multicast events, configurable replay.
66. How do you collect a Flow safely on the UI?
- Use
repeatOnLifecycle(STARTED)orcollectAsStateWithLifecycle. - This stops collection when the screen is not visible, saving resources.
67. What is the difference between cold and hot streams?
- Cold — starts producing per collector (Flow).
- Hot — emits regardless of collectors (StateFlow/SharedFlow).
68. How do you test a ViewModel?
- Inject fake repositories; use a test dispatcher and
runTest. - Assert emitted states for given inputs — no Android framework needed.
69. Unit tests vs instrumented tests vs UI tests.
- Unit — fast, on the JVM (logic, ViewModels).
- Instrumented — run on a device (need Android APIs).
- UI — Espresso/Compose test rules verify screens.
70. What is the difference between Espresso and Compose UI testing?
- Espresso — tests View-based UI.
- Compose testing — uses a
composeTestRulewith semantics matchers.
71. What is the difference between an inline function and a normal function?
- An
inlinefunction copies its body (and lambdas) to the call site, reducing lambda object overhead. - Used heavily in higher-order functions for performance.
72. What are higher-order and extension functions?
- Higher-order — takes/returns a function (e.g.
filter { }). - Extension — adds a method to an existing type without subclassing.
73. What is the difference between val and var, and lateinit vs lazy?
valread-only;varmutable.- lateinit — non-null var initialised later (no default).
- lazy — computed once on first access (val).
74. How does Jetpack Compose differ from the View system (quick)?
- Declarative Kotlin functions vs imperative XML + findViewById.
- State changes trigger recomposition; less boilerplate.
75. What is the difference between a singleton and a static in Kotlin?
- Kotlin has no
static; useobjectfor a singleton andcompanion objectfor class-level members.
76. What is ANR vs crash vs jank?
- ANR — main thread blocked.
- Crash — an unhandled exception.
- Jank — dropped frames (slow rendering).
77. How do you reduce app startup time?
- Defer non-essential init; use App Startup / lazy initialization.
- Avoid heavy work in
Application.onCreate; measure cold start.
78. How do you reduce APK/app size?
- Enable R8 shrinking, use AAB, compress/vector drawables, remove unused resources, split by ABI.
79. How do you profile and improve performance?
- Use the Android Studio Profiler (CPU, memory, network) and Macrobenchmark.
- Fix nested layouts, main-thread work, and excessive allocations.
80. What is the difference between a process and a thread on Android?
- Each app runs in its own process (sandbox); a process has multiple threads.
- The main thread handles UI; the OS can kill background processes.
81. What happens during process death and how do you handle it?
- The OS kills a backgrounded app to free memory; in-memory state is lost.
- Restore via SavedStateHandle / onSaveInstanceState and persisted data.
82. What is the difference between an implicit and an explicit broadcast, and recent restrictions?
- Implicit broadcasts (no target) are restricted from manifest registration since Android 8 to save battery.
- Prefer context-registered receivers or WorkManager.
83. How does image loading work efficiently (Coil/Glide)?
- Downsample to the display size; cache in memory and disk; load off the main thread.
- Never load full-resolution images into small views (OOM).
84. What is the difference between Gson, Moshi and kotlinx.serialization?
- All convert JSON; Moshi/kotlinx.serialization are Kotlin-friendly and faster than reflection-heavy Gson.
- kotlinx.serialization is multiplatform.
85. How do you implement pagination?
- Load pages as the user scrolls (cursor-based preferred); show a loading footer.
- The Paging 3 library + RemoteMediator combine network and database.
86. What is the difference between Bundle savedInstanceState being null or not in onCreate?
- null — fresh start; initialise defaults.
- non-null — recreated (rotation/process death); restore saved state.
87. How do you handle different screen sizes and densities?
- Use ConstraintLayout, dp/sp, density-qualified resources, and responsive layouts (window size classes).
- Test on phones and tablets.
88. How do you keep an app smooth at 60fps?
- Keep the main thread free; do I/O off-thread.
- Flatten layouts, recycle lists, cache and downsample images, avoid allocations in hot paths.
- Profile on real low-end devices.
Interview tip: structure every answer as “what it is → why it matters → a real example or pitfall”, and mention the modern recommended approach (coroutines, Compose, WorkManager) to show you’re current.