Skip to content
Tutorials Center
My learning

Topics

Lesson 103 of 104 ยท Practice and Review

Android Interview Questions

Forty-seven Android interview questions with concise answers on lifecycle, Compose, Views, fragments, coroutines, Room, architecture and performance, plus runnable stand-ins.

Android interviews usually start with the platform (lifecycle, components, process death), move on to Compose and state, then test whether you can structure an app: ViewModel, coroutines, Room, repositories. The last questions are about judgment: performance, security and testing. This lesson collects forty-seven questions in that order, each with an answer short enough to say out loud, and five runnable stand-ins for the questions where watching the behavior settles the argument.

A strong answer has three parts: the rule, a small example, and the reason the platform works that way. The real Android and Compose code in this lesson is read-only, because the site has no Android SDK or emulator. The TryIt blocks are plain Kotlin programs that model the behavior, and each one says what it models. Follow the links for the full lesson on a topic.

flowchart LR
    A["Platform<br/>(lifecycle, components)"] --> B["UI<br/>(Compose, state)"]
    B --> C["Structure<br/>(ViewModel, coroutines, data)"]
    C --> D["Judgment<br/>(performance, security, tests)"]

The order interviews tend to follow, and the order of the sections below.

Platform and lifecycle (1 to 8)

1. What are the four main app component types? Activities (a screen entry point), services (work without UI), broadcast receivers (system or app events) and content providers (shared data). Each is declared in the manifest. See The Manifest and Resources.

2. Describe the Activity lifecycle. onCreate builds the UI, onStart makes it visible, onResume gives it focus, and the mirror callbacks are onPause, onStop and onDestroy. Visible does not mean focused: a dialog or split-screen neighbor can pause an activity that is still on screen. See The Activity Lifecycle.

3. What happens to an Activity on rotation? By default it is destroyed and recreated with the new configuration. State in plain fields and remember is lost; ViewModel and saved state survive. See Configuration Changes and Saved State.

4. What is process death and how does it differ from rotation? The system kills the whole app process in the background to free memory. Nothing in memory survives, including ViewModels. Only saved state (rememberSaveable, SavedStateHandle) and persistent storage come back.

5. Where should you do work that must stop when the user leaves? In a scope tied to the lifecycle: viewModelScope for screen logic, or collection with repeatOnLifecycle or collectAsStateWithLifecycle in the UI, so work stops when the screen is not started.

6. What is the difference between an explicit and an implicit Intent? An explicit intent names the target component. An implicit intent describes an action and data, and the system picks a matching component by its intent filters. See Intents.

7. Why use the Activity Result API instead of startActivityForResult? Contracts such as ActivityResultContracts.RequestPermission are type-safe, survive recreation and are registered once, so the result is not lost when the Activity is recreated.

8. Which Context do you use where? Use the Activity for UI work such as dialogs and themes. Use the application context for long-lived objects, because holding an Activity reference in a singleton leaks the whole screen.

Check it: callback order on rotation

The stand-in below models the callback order the platform runs when a screen rotates, including the state save and restore. It is a model of the order, not the real framework.

Kotlin Rotation callback order (stand-in)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with readln()), it gets the next line from this box.

The real order has a few more callbacks, but the pattern is the point: save before destroy, restore after start.

Compose and UI state (9 to 18)

9. What is Compose and how does it differ from Views? Compose builds UI from Kotlin functions that describe the screen for a given state. The framework re-runs the affected functions when state changes. Views are mutable objects you find and update by hand. See Thinking in Compose.

10. What is recomposition? Re-running composable functions whose inputs or read state changed. Compose skips functions whose inputs are equal, so composables must be fast, free of side effects and tolerant of running often or in any order.

11. What is the difference between remember and rememberSaveable? remember keeps a value while the composable stays in the composition; it is lost on rotation. rememberSaveable also stores the value in saved state so it survives recreation and process death, if the value can be saved in a Bundle or has a custom Saver.

12. What is state hoisting? Moving state to the caller and passing it down as a value, with a callback for changes. The composable becomes stateless, easy to preview and test. See State Hoisting.

13. When do you use derivedStateOf? When one state changes often and a value computed from it changes rarely, such as listState.firstVisibleItemIndex > 0. Readers then recompose only when the derived result changes.

14. What is the difference between LaunchedEffect, rememberCoroutineScope and DisposableEffect? LaunchedEffect(key) runs a suspend block when entering the composition and restarts when the key changes. rememberCoroutineScope gives a scope for coroutines started from events such as clicks. DisposableEffect registers something and must undo it in onDispose. See Side Effects.

15. Why does modifier order matter? Modifiers apply outside in. padding(16.dp).background(red) pads, then paints inside the padding; background(red).padding(16.dp) paints everything, then pads inside it. See Modifiers.

16. Why give LazyColumn items keys? Keys let Compose track items by identity, so remembered state, animations and scroll position follow the item when the list changes. Without keys, items are matched by position. See Lazy Lists.

17. What makes a type stable, and why does it matter? Stable types report changes through Compose state or never change, so Compose can skip functions whose parameters are equal. With strong skipping mode, on by default in recent Kotlin Compose compilers, unstable parameters are compared by instance and skipping works in many more cases. See Recomposition and Stability.

18. How do you make a Compose screen adapt to tablets and foldables? Read the window size class and choose a layout from it, for example list and detail side by side on wide windows. See Adaptive Layouts.

Check it: skipping and equality

This stand-in models skipping: a function is called again only if its argument is not equal to the previous one. A data class compares by value and a plain class by instance.

Kotlin Skip when inputs are equal (stand-in)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with readln()), it gets the next line from this box.

Real Compose has more rules (stability annotations, strong skipping), but this is why creating a new object on every recomposition can defeat skipping.

Architecture and state holders (19 to 26)

19. What is the recommended app architecture? A UI layer (composables plus a ViewModel holding UI state), an optional domain layer of use cases, and a data layer of repositories over local and remote sources. Data flows up, events flow down. See Architecture Layers.

20. What does a ViewModel survive, and what is it for? It survives configuration changes, because it lives in a store that outlives the Activity. It holds screen state, launches coroutines in viewModelScope, and is cleared when the screen is gone. It does not survive process death. See ViewModel.

21. What must a ViewModel never hold? An Activity, a View or a composable's Context, since they die on rotation and would leak. Use the application context through AndroidViewModel only when you must, and prefer injecting what you need.

22. How do you model screen state? As one immutable UiState, either a data class or a sealed hierarchy with loading, content and error cases, exposed as StateFlow. User actions go in as functions or events. See UI State and Events.

23. StateFlow or LiveData? StateFlow, in new code: it is Kotlin-native, works with flow operators and has a required initial value. LiveData is lifecycle-aware but Android-specific. Collect StateFlow in the UI with collectAsStateWithLifecycle. See StateFlow in Compose.

24. How do you send a one-off event such as a snackbar? Prefer modelling it as state that the UI consumes and clears. If you use a stream, a Channel buffers the event until a collector exists, while a SharedFlow with no replay drops events when nobody is collecting.

25. What does stateIn(scope, SharingStarted.WhileSubscribed(5_000), initial) do? Turns a cold flow into a StateFlow that is active only while subscribed, with a five-second grace period so a rotation does not restart the upstream.

26. What is the repository pattern? One class that hides where data comes from. It exposes domain-friendly data, merges local and remote sources, and is the single source of truth for a data type. See Repository Pattern.

Check it: one-off events

This stand-in shows the difference in question 24 with real coroutines: a SharedFlow with no replay loses an event emitted before anyone collects, while a buffered Channel keeps it.

Kotlin SharedFlow vs Channel for one-off events

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with readln()), it gets the next line from this box.

The real lesson is wider than the stand-in: even a Channel can lose an event if the UI is gone, which is why state-based events are often safer.

Coroutines, flows and background work (27 to 31)

27. What are the main dispatchers? Main for UI, IO for blocking input and output, Default for CPU work. viewModelScope uses Main.immediate. See Coroutines on Android.

28. What does main-safe mean? A suspend function that can be called from the main thread because it moves blocking work to the right dispatcher itself, usually with withContext(Dispatchers.IO).

29. What happens to coroutines when the ViewModel is cleared? viewModelScope is cancelled, which cancels every coroutine in it. Cancellation is cooperative: suspend functions check it, and you must rethrow CancellationException if you catch it.

30. How do you collect a flow safely in a UI? With repeatOnLifecycle(Lifecycle.State.STARTED) or collectAsStateWithLifecycle, so collection stops when the app goes to the background. See Collecting Flows Safely.

31. WorkManager, service or coroutine? A coroutine for work tied to the screen, WorkManager for deferrable work that must still happen if the app closes (uploads, sync), a foreground service for user-visible ongoing work such as playback. See WorkManager.

Check it: scope cancellation

This stand-in uses a real coroutine scope as a model of viewModelScope and shows work being cancelled when the owner is cleared.

Kotlin Clearing the owner cancels its coroutines (stand-in)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with readln()), it gets the next line from this box.

Data, networking and dependency injection (32 to 36)

32. How does Room work? You annotate entities, DAOs and a database class. A processor generates the SQL code at build time. DAO functions can be suspend or return Flow, which re-emits when the observed tables change. Room refuses queries on the main thread by default. See Room Basics.

33. How do you change a Room schema safely? Bump the database version and provide a Migration (or an auto-migration) that transforms the old schema, and test it. Dropping the database loses user data. See Room Relations and Migrations.

34. DataStore or SharedPreferences? DataStore: asynchronous, Flow-based, transactional and safe on the main thread. SharedPreferences can block the UI thread and has weak error handling. See DataStore.

35. How does offline-first work? The local database is the single source of truth and the UI observes it. The network only refreshes the database, and failures leave the existing data in place. See Error Handling and Offline-first.

36. Why use dependency injection? Objects receive their dependencies instead of creating them, so you can swap fakes in tests and change implementations in one place. Hilt generates the wiring from annotations. See DI Concepts and Hilt.

More questions: Views, fragments and the system (37 to 47)

These questions come up most often in interviews for apps that still contain Views and fragments, and for roles that touch the platform itself.

37. What is the difference between a View and a ViewGroup? A View draws itself and handles input (a TextView, a Button). A ViewGroup is a View that also contains child views and decides where to put them (LinearLayout, ConstraintLayout, RecyclerView). Layout runs in two passes: measure (each parent asks each child how big it wants to be) and layout (the parent assigns positions). See XML Layouts.

38. What is the difference between a Fragment and an Activity? An Activity is a system-registered entry point with its own window, declared in the manifest. A Fragment is a reusable piece of UI and behavior that lives inside an Activity, is managed by a FragmentManager, and has its own lifecycle plus a separate view lifecycle (viewLifecycleOwner). Modern single-activity apps use one Activity and many destinations. See Fragments.

39. What are intent filters and where do they matter? An intent filter in the manifest declares which actions, categories and data a component can handle, so the system can resolve implicit intents to it. Deep links, share targets and NFC dispatch all rely on filters. Since Android 12, any component with a filter must declare android:exported explicitly. See Intents and Back stack and deep links.

40. What are AIDL and Binder? Binder is Android's inter-process communication mechanism: a kernel driver that lets one process call methods on an object in another process. AIDL (Android Interface Definition Language) describes such an interface in a file so the build generates the proxy and stub code. You need AIDL only when a bound service must serve clients in other processes and handle several threads at once; for a same-process service, a plain Binder subclass is simpler, and a Messenger suits simple cross-process requests. Arguments must be Parcelable, and a transaction has a size limit of about 1 MB.

41. What is an ANR and how do you avoid one? "Application Not Responding" appears when the main thread cannot respond in time: roughly 5 seconds for an input event and about 10 seconds for a foreground broadcast receiver (the exact limits vary by component and version). Typical causes are blocking work on the main thread (disk, network, long loops), lock contention and slow onReceive or service callbacks. Avoid it by moving work to coroutines on Dispatchers.IO or Default, turning on StrictMode in debug builds, and reading the traces in Android vitals in the Play Console. See Performance.

42. What are cold, warm and hot starts? A cold start creates the process, runs Application.onCreate and then creates the first Activity: the slowest. A warm start has the process alive but must recreate the Activity, for example after it was destroyed in the background. A hot start only brings an existing Activity back to the foreground. Cold start is the number to optimize: defer initialization, use the App Startup library and ship baseline profiles.

43. What kinds of Context are there? The Application context lives as long as the process, an Activity context is tied to one screen and carries its theme, and a Service is also a Context. Use the application context for anything that outlives a screen, and the Activity context for dialogs, themes and starting UI. See Context Explained.

44. How does RecyclerView work internally? It creates only enough ViewHolders to fill the screen and recycles the ones that scroll out of view by rebinding them to new data. The LayoutManager positions views, the Adapter creates and binds holders, and DiffUtil (usually through ListAdapter) computes the minimal set of changes between two lists on a background thread. Holders that are still attached are cached, and detached ones go to a shared pool keyed by view type. Lazy lists in Compose play the same role but compose only the visible items. See RecyclerView.

45. LiveData or StateFlow? Both hold a value and notify observers. LiveData is lifecycle-aware by itself, belongs to Android and offers only simple transformations. StateFlow is Kotlin-native, always has a value, skips equal values, works with all flow operators and is not lifecycle-aware, so you collect it with repeatOnLifecycle or collectAsStateWithLifecycle. Use StateFlow in new code and bridge LiveData with observeAsState or asFlow when you inherit it. See LiveData and Lifecycle.

46. What are Handler, Looper and MessageQueue? A thread that processes messages has one Looper, which loops forever taking messages from its MessageQueue. A Handler is attached to a Looper: you post a Runnable or Message (optionally delayed) and the Looper runs it on its own thread, in time order. The framework creates the main thread's Looper, and every UI callback is a message on it. Dispatchers.Main in coroutines is built on a main-thread Handler, and Handler(Looper.getMainLooper()).post { } is the older way to get onto the main thread.

47. Why can only the main thread touch views? Views are not thread-safe, and layout and drawing from several threads would need locks everywhere. Android checks the thread in ViewRootImpl and throws CalledFromWrongThreadException. Do background work elsewhere and hand the result to the main thread.

Check it: a Looper and Handler

This stand-in models question 46: one thread runs messages from a queue ordered by delivery time, and other threads only add messages. It is a model of the idea, not the real Looper.

Kotlin A tiny Looper and Handler (stand-in)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with readln()), it gets the next line from this box.

All callbacks run on one thread in time order, and the worker thread only enqueues. That is why updating a view from the Looper's thread is safe and from any other thread is not.

Platform and library questions (48 to 58)

A second round of short answers, mostly about the platform itself and the libraries around it.

48. What are the main components of an Android application? Four component types are registered with the system: Activities (screens), Services (work without UI), Broadcast Receivers (react to events) and Content Providers (share data). Around them sit resources, the manifest and, in modern apps, a Jetpack layer (ViewModel, Room, Navigation). See Android components.

49. What is the Dalvik Virtual Machine, and how does ART differ? Dalvik was the original runtime: it ran DEX bytecode, interpreted it and later added a JIT compiler. ART (default since Android 5.0) compiles DEX to native code on the device (ahead of time, then combined with JIT and profile-guided compilation in later versions) with an improved garbage collector. Apps start and run faster and use less battery. See Versions, boot process, Zygote and garbage collection and DEX, ART and desugaring.

50. What are the disadvantages of Android as a platform? Fragmentation (many devices, versions and manufacturer skins to test), a longer tail of old OS versions in use, a steep build-system learning curve, battery and background restrictions that change each release, and a slower emulator than a real device. Most of the platform's complexity exists to handle those limits.

51. What is AIDL? A language for describing a Binder interface so the build generates the code for calls between processes. Use it only for bound services used by other apps or processes with concurrent callers. See question 40 and AIDL and IPC.

52. What is Dagger, and when would you use it? Dagger is a compile-time dependency injection framework: it generates the code that builds objects and wires dependencies, so mistakes show up at compile time and there is no reflection at run time. Use it (usually through Hilt) when an app has many classes with shared dependencies, scoped lifetimes and tests that must swap implementations. A tiny app can inject by hand through constructors. See Dagger 2 and Hilt.

53. What is Android KTX? A set of Kotlin extension functions and properties over Jetpack and platform APIs that makes them shorter and more idiomatic, for example prefs.edit { putInt("n", 1) }, view.isVisible = false or bundleOf("id" to 1). It adds no new behavior. See Kotlin on Android.

54. What is pagination and why use it? Loading a long list in pages as the user scrolls instead of all at once. It keeps memory and network use low, makes the first screen appear faster and avoids loading rows nobody sees. Jetpack Paging 3 implements it with a PagingSource and PagingData. See Paging.

55. What is an inline function in Kotlin and why does it matter on Android? A function marked inline is copied into its call sites, so lambdas passed to it need no object allocation. That is why many small helpers (let, apply, KTX edit {}) are free at run time. Use inline for small functions that take lambdas, crossinline/noinline for special lambda cases, and avoid it on large functions, which bloats the bytecode.

56. What is Multidex? A DEX file can reference at most 65,536 methods. Apps over that limit need several DEX files. From Android 5.0 (API 21) the runtime supports it natively, so minSdk 21 or higher needs nothing extra; for older devices you add the multidex library. See DEX, ART and desugaring.

57. What is onViewCreated() in the Fragment lifecycle? It runs right after onCreateView returns the view and before the view's state is restored. It is the right place to find or bind views, set adapters and start observing state with viewLifecycleOwner, because the view exists but the user has not seen it yet. See Fragments.

58. What is the difference between MVC, MVP and MVVM? All three separate data, UI and logic. In MVC the Controller (often an Activity) mediates; on Android it tends to grow huge. In MVP the Presenter holds the logic and talks to the View through an interface, which makes it testable but needs boilerplate. In MVVM the ViewModel exposes state that the View observes and never references the View, which suits lifecycle-aware observation. Modern Android recommends MVVM-style state holders with unidirectional data flow. See Architecture layers.

Performance, security and testing (bonus answers)

Interviewers often finish with an open question. These short answers cover the usual ones.

  • How do you find jank? Frames must finish within about 16 ms at 60 Hz. Use the Layout Inspector's recomposition counts, the profiler or Perfetto, and macrobenchmarks, and move work out of composition. See Performance.
  • How do you speed up startup? Defer initialization, add baseline profiles, and keep Application.onCreate light.
  • How do you find memory leaks? Look for objects that outlive their screens, such as an Activity in a static field, and use a leak detector.
  • What is the basic security checklist? Do not export components unless needed, use the Keystore for keys, keep secrets out of the APK, use HTTPS, and be careful with WebView. See Securing Your App.
  • What would you test? ViewModels and reducers with fast unit tests and fakes, Compose screens through the semantics tree, and Room or navigation with instrumented tests. See Testing ViewModels.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. A user types in a text field, then rotates the phone. The text uses remember { mutableStateOf("") }. What happens?

    remember lives as long as the composition. Rotation recreates the Activity, so the value starts again. rememberSaveable would keep it.
  2. 2. Which statement about ViewModel is correct?

    A ViewModel outlives the Activity instance, so rotation does not reset it. If the system kills the process, it is gone. Never hold an Activity in it.
  3. 3. Why is WhileSubscribed(5_000) commonly used with stateIn?

    The grace period covers short gaps such as a rotation, while still stopping work when the user really leaves the screen.
  4. 4. Which approach loses an event when nobody is collecting at the moment it is emitted?

    A SharedFlow without replay delivers only to current collectors. A buffered channel keeps the event until it is received.
  5. 5. What does derivedStateOf help with?

    Readers depend on the derived result, so they recompose only when that result changes, not on every change of the input state.

Summary

  • Know the lifecycle order, what survives rotation, and how process death differs.
  • remember is lost on rotation; rememberSaveable and the saved state handle are not; ViewModel survives rotation but not process death.
  • Hoist state, use keys in lists, and use derivedStateOf for rarely changing results of busy state.
  • Model screens as one immutable UI state and expose it as StateFlow, collected with lifecycle awareness.
  • Coroutine scopes tie work to a lifecycle; cancellation is cooperative.
  • Room, DataStore and a repository make the local store the single source of truth.
  • Mention measurement, security and testing when asked about quality.
  • The Android code here is read-only; the TryIt blocks are Kotlin stand-ins for the behavior.

Next: Android Cheat Sheet