Kotlin basics
Language questions that come first in most Android rounds.
Q1.How does Kotlin handle null safety?
Types are non-null by default. A nullable type needs a ?, as in String?, and the compiler forces you to handle null using safe calls ?., the Elvis operator ?:, smart casts after a null check, or !!, which throws if the value is null.
Q2.What is the difference between val and var?
val is a read-only reference that cannot be reassigned, var can be reassigned. A val holding a mutable list can still have its contents changed.
Q3.What is a data class?
A class marked data gets equals, hashCode, toString, copy and component functions generated from its primary constructor properties. It is the standard choice for models and UI state.
Q4.What is a sealed class or sealed interface?
It restricts which subclasses exist, all known at compile time. A when over a sealed type can be exhaustive without an else branch, which makes it ideal for UI states like Loading, Success and Error.
Q5.What are extension functions?
They add functions to an existing class without inheriting from it, such as fun String.isEmail(): Boolean. They are resolved statically, so they cannot override member functions.
Q6.Explain the scope functions let, run, with, apply and also.
They run a block on an object. let and also refer to it as it; run, with and apply use this. apply and also return the object itself, which suits configuration and side effects; let, run and with return the block's result.
Q7.What is the difference between object and companion object?
object declares a singleton. A companion object is a singleton tied to a class, used for factory methods and constants, similar to static members in Java.
Q8.What is lateinit and when do you use lazy?
lateinit var promises a non-null var will be set before use, common for dependency-injected fields. by lazy creates a val on first access and caches it, and is thread-safe by default.
Q9.What are higher-order functions and inline functions?
A higher-order function takes or returns a function. Marking it inline copies the function body and lambda into the call site, removing lambda allocation and allowing non-local returns.
Q10.What is the difference between == and === in Kotlin?
== checks structural equality by calling equals. === checks referential equality, whether both references point to the same object.
Q11.What are generics variance keywords in and out?
out T means the type only produces T, so List<out Animal> can accept a list of Dog. in T means it only consumes T, as in Comparator. This is declaration-site variance, similar to Java wildcards.
Android fundamentals
Platform questions on components and lifecycle.
Q12.What are the four Android app components?
Activities for screens, Services for background work without UI, Broadcast Receivers for system or app events, and Content Providers for sharing data between apps. Each is declared in the manifest.
Q13.Explain the Activity lifecycle.
onCreate sets up the activity, onStart makes it visible, onResume makes it interactive. onPause runs when it loses focus, onStop when it is no longer visible and onDestroy before it is destroyed. Rotation destroys and recreates the activity by default.
Q14.What is process death and how do you handle it?
The OS can kill your app process while it is in the background. When the user returns, Android recreates the last activity, but in-memory data is gone. Save small UI state with SavedStateHandle or rememberSaveable and reload the rest from the database.
Q15.What is an Intent?
An Intent is a message to start an activity, service or broadcast. Explicit intents name a specific component in your app; implicit intents describe an action like viewing a URL and let the system choose an app.
Q16.What is a Fragment and why are they less common now?
A Fragment is a reusable piece of UI with its own lifecycle inside an activity. They brought complex lifecycle and back stack issues. With Compose, most new apps use a single activity and composable screens with Navigation Compose.
Q17.What is a ViewModel?
A Jetpack class that holds UI state and survives configuration changes like rotation. It is scoped to an activity, fragment or navigation destination and is cleared when that owner is finished. It should not hold references to views or activities.
Q18.What is ANR?
Application Not Responding is shown when the main thread is blocked too long, for example about five seconds for input events. Causes include disk or network I/O, heavy computation or locks on the main thread.
Q19.What is the difference between Service, foreground service and WorkManager?
A Service runs work without UI but background limits restrict it. A foreground service shows a persistent notification and suits user-visible ongoing tasks like music playback or navigation, with a declared type. WorkManager is the recommended API for deferrable, guaranteed background work.
Q20.What is the Android manifest used for?
It declares the package's components, permissions, the minimum and target SDK through Gradle merge, intent filters for deep links and features the app requires.
Q21.How do runtime permissions work?
Dangerous permissions such as camera or location must be requested at runtime with the Activity Result API. Check if they are granted, show a rationale when needed and handle permanent denial by pointing users to settings.
Q22.What are launch modes for an activity?
They control how a new activity instance relates to the back stack: standard creates a new instance each time, singleTop reuses the top instance and calls onNewIntent, singleTask keeps one instance in its task and singleInstance puts it in a task of its own. Intent flags can override them.
Q23.How do you store small settings on Android today?
Jetpack DataStore. Preferences DataStore stores key-value pairs, and Proto DataStore stores typed objects. It is asynchronous with Flow and avoids the main thread disk reads that SharedPreferences could cause.
Coroutines and Flow
Async questions that appear in nearly every Kotlin interview.
Q24.What is a coroutine?
A coroutine is a lightweight unit of work that can suspend without blocking a thread. Thousands can run on a few threads. Suspend functions read like sequential code but can pause for network or disk work.
Q25.What is structured concurrency?
Every coroutine runs inside a scope, and a parent waits for its children. If the scope is cancelled, all children are cancelled. On Android, viewModelScope and lifecycleScope cancel work automatically when the owner ends.
Q26.What is the difference between launch and async?
launch starts a coroutine that returns a Job and no result. async returns a Deferred, and you call await() to get the result. Use async to run several independent calls in parallel.
Q27.What are dispatchers?
They decide which threads a coroutine runs on. Dispatchers.Main for UI, Dispatchers.IO for blocking I/O, and Dispatchers.Default for CPU-heavy work. Use withContext to switch inside a suspend function.
Q28.What is the difference between Job and SupervisorJob?
With a regular Job, one failed child cancels the parent and all siblings. With a SupervisorJob, a child failure does not affect siblings. viewModelScope uses a SupervisorJob.
Q29.What is Flow?
Flow is a cold asynchronous stream that emits values over time. Nothing runs until it is collected. Room, DataStore and many libraries return Flow so the UI updates when data changes.
Q30.What is the difference between StateFlow and SharedFlow?
StateFlow always has a current value, replays it to new collectors and skips equal consecutive values, so it fits UI state. SharedFlow is configurable with replay and buffer and suits one-off events.
Q31.How do you collect Flow safely in the UI?
In Compose use collectAsStateWithLifecycle(). In views use repeatOnLifecycle(Lifecycle.State.STARTED) inside lifecycleScope, so collection stops when the app is in the background.
Q32.How do you handle errors in coroutines?
Use try/catch around suspend calls, the catch operator on flows, and a CoroutineExceptionHandler for uncaught exceptions in launch. Never catch CancellationException without rethrowing, or cancellation breaks.
Jetpack Compose and architecture
Modern Android questions for mid and senior roles.
Q33.What is Jetpack Compose?
Android's declarative UI toolkit. You write composable functions that describe the UI for a given state, and Compose updates only what changed when the state changes.
Q34.What is recomposition?
When state read by a composable changes, Compose re-runs that function to update the UI. It can skip composables whose inputs have not changed, so stable inputs and small composables improve performance.
Q35.What is the difference between remember and rememberSaveable?
remember keeps a value across recompositions but loses it on configuration change or process death. rememberSaveable stores it in the saved instance state bundle, so it survives both.
Q36.What is state hoisting?
Moving state out of a composable to its caller, which passes the value and an event callback down. It makes composables stateless, reusable and easy to test.
Q37.What are side effects in Compose?
Code that changes something outside the composable. Use LaunchedEffect to run a coroutine tied to a key, DisposableEffect for setup and cleanup, and SideEffect to publish state to non-Compose code after each successful recomposition.
Q38.What is derivedStateOf?
It creates state computed from other state that updates only when the result changes, for example showing a scroll-to-top button only when the first visible item index passes a threshold.
Q39.How does Hilt work?
Hilt is a dependency injection library built on Dagger. You annotate the Application with @HiltAndroidApp, entry points with @AndroidEntryPoint, ViewModels with @HiltViewModel, and define bindings in modules. It generates the code at compile time.
Q40.What is Room?
Room is a SQLite abstraction with entities, DAOs and a database class. It verifies SQL queries at compile time, supports Flow and suspend functions and handles migrations.
Q41.What is the recommended Android app architecture?
A UI layer with composables and ViewModels exposing UI state, an optional domain layer with use cases, and a data layer of repositories and data sources. Data flows down as state, events flow up.
Q42.What does R8 do?
R8 shrinks, optimises and obfuscates code in release builds and removes unused resources. Keep rules protect classes accessed by reflection, such as some serialisation models.
Q43.What are Gradle version catalogs?
A libs.versions.toml file that centralises dependency versions and plugin IDs, so modules reference libs.retrofit instead of repeating coordinates.
Q44.What are build types and product flavors?
Build types such as debug and release change how the app is built, for example minification and signing. Flavors such as free and paid or dev and prod change what is built, like app ID suffixes and API URLs. Combined they form build variants.
Q45.How does navigation work in Compose?
Navigation Compose defines a NavHost with destinations. Newer versions support type-safe routes using serializable classes or objects instead of string routes, and arguments are read through SavedStateHandle in the ViewModel.
Scenario questions
How you would handle real problems on the job.
Q46.A screen loses the user's typed text after rotation. How do you fix it?
In Compose, store the text with rememberSaveable or in a ViewModel. In views, give EditText an ID so the system saves it, or keep it in the ViewModel. Also test with Don't keep activities to simulate process death.
Q47.Your app shows ANRs in Play Console. How do you investigate?
Open Android vitals and read the ANR traces to see what the main thread was doing. Look for disk reads like SharedPreferences commits, database queries, locks or broadcast receivers doing heavy work. Move the work to coroutines on IO or Default and use StrictMode in debug builds.
Q48.How would you build an image-heavy feed?
Use LazyColumn or RecyclerView with stable keys, load images with Coil or Glide sized to the view, cache in memory and on disk, use Paging 3 for data, and prefetch the next page.
Q49.How do you sync data every few hours even if the app is closed?
Use a PeriodicWorkRequest with WorkManager, set constraints such as network connected and battery not low, make the worker idempotent and enqueue it as unique work so duplicates are not scheduled.
Q50.How would you migrate a module from RxJava to coroutines?
Start at the edges with interop libraries like kotlinx-coroutines-rx3, convert repository methods to suspend functions and Flow, update ViewModels, and remove Rx once nothing depends on it. Keep tests passing at each step.
Q51.Compose screens recompose too often. How do you find the cause?
Use Layout Inspector recomposition counts and Compose compiler reports. Common causes are unstable parameters like plain List types, reading state too high in the tree and lambdas that capture changing values. Use immutable collections, stability configuration and defer state reads.
Q52.How would you secure an API key used by the app?
Treat any key in the APK as public. Restrict it on the provider side by package name and signing certificate, proxy sensitive calls through your backend, and use Play Integrity to check requests come from a genuine install. Keep it out of version control with local.properties or CI secrets.
How to prepare for the interview
- Practise explaining process death and how your app restores state; it separates juniors from mid-level candidates.
- Know the difference between StateFlow, SharedFlow and LiveData and why you would pick one.
- Have a Compose screen you built that you can describe, including how it handles recomposition.
- Revise Gradle basics: build types, flavors, version catalogs and what R8 does.