Kotlin
225 bites tagged Kotlin — interview questions with model answers, and 60-second explainers.
Combine two network sources using Coroutines and Flow
Tests your grasp of async data combination and state management. A good answer uses Flow.combine in a ViewModel, fed by a Repository, emitting a sealed class for UI state (Loading, Success, Error). A red flag is trying to combine state in the UI layer itself.
How do you share a ViewModel between Fragments?
Tests your understanding of ViewModel lifecycle scoping beyond a single screen. To share, scope the ViewModel to the parent Activity or a navigation graph using `activityViewModels()` or `navGraphViewModels()`.
Why is LiveData<Boolean> bad for one-time ViewModel events?
Tests if you know LiveData holds state, not events. A good answer explains that LiveData re-emits on configuration changes, causing repeated events. The solution is to model events as part of the UI state and consume them.
How do you pass data between Fragments with Jetpack Navigation?
Tests knowledge of modern, type-safe argument passing. A good answer defines the argument in the nav graph XML, uses the Safe Args plugin to generate Directions/Args classes, navigates with the action, and retrieves the data in the destination via `by…
Explain ViewModel, Repository, and Data Source in MVVM
This tests your understanding of separation of concerns. A great answer defines ViewModel (UI state), Repository (data abstraction), and Data Sources (implementation), then explains the unidirectional data flow.
How do you diagnose and fix excessive recomposition in Jetpack Compose?
This tests your grasp of Compose's stability system. First, use Layout Inspector to find high-recomposition areas. Then, enable and analyze the Compose compiler report to diagnose unstable parameters (like List) or lambdas.
`remember` vs. `rememberSaveable`: When and why to use each?
Tests understanding of state survival in Compose. A good answer contrasts `remember` (for composition) with `rememberSaveable` (for activity recreation/process death), explaining its use of the `Bundle` mechanism. A red flag is confusing the two lifecycles.
Explain Recomposition in Jetpack Compose
This tests your core understanding of Compose's declarative model. Explain that recomposition is re-running composables when state they read changes. Mention that Compose optimizes by only recomposing the nearest scope and skipping composables with stable…
What is the purpose of `remember` in Jetpack Compose?
This tests your grasp of Compose's recomposition lifecycle. A good answer explains `remember` caches an object across recompositions, preventing state loss. It's used with `mutableStateOf` to hold the same state instance.
Explain ConstraintLayout, Chains, and Barriers
Tests your grasp of performant Android UIs. Explain how ConstraintLayout flattens hierarchy, use chains to distribute groups of views (e.g., packed), and use barriers to align elements against dynamic content.
Explain app restoration after Android process death
Tests your grasp of process death vs. configuration changes. A good answer explains that the entire app process is recreated, starting with onCreate, and state must be restored from the SavedStateHandle.
When and why to use a Foreground Service?
Tests your grasp of Android's background execution limits. A great answer explains they're for user-visible tasks like music playback, requires `startForegroundService()`, and must show a notification within 5 seconds.
How does a ViewModel survive configuration changes?
Tests understanding of lifecycle-aware components. ViewModels are retained by a ViewModelStore owned by the Activity/Fragment, which survives configuration changes. The ViewModel is cleared only when its scope is permanently finished.
Trace an Activity's lifecycle when a user navigates away and returns
This tests your understanding of resource management and state preservation, not just memorization. A great answer traces onPause -> onStop when leaving, and onRestart -> onStart -> onResume when returning, explaining what happens in each.
How would you debug an app crash in Android Studio?
This tests your systematic debugging process. A good answer starts with Logcat to find the stack trace, then uses breakpoints to inspect program state *before* the crash occurs. A red flag is randomly adding print statements instead of using the debugger.
Purpose and Key Elements of AndroidManifest.xml
Tests if you know the manifest is the app's contract with the Android OS. A good answer defines its role and lists key elements like activities, permissions, and the launcher intent. A red flag is calling it just a generic 'config file'.
Implement a type-safe DSL for a UI component in Kotlin
This tests your ability to design clean, hierarchical APIs using Kotlin's idiomatic features. A great answer defines model classes, then uses higher-order functions with lambdas with receiver to create a nested structure, and mentions `@DslMarker` for scope…
What is a reified type parameter in Kotlin?
Tests your grasp of JVM type erasure and Kotlin's solution. Explain that `reified` makes a generic type accessible at runtime inside an `inline` function, avoiding manual `Class` passing. A red flag is failing to link `reified` directly to `inline` functions.
How does coroutine cancellation work internally?
Tests your grasp of cooperative cancellation. A good answer explains that `cancel()` sets a flag, `suspend` functions check it and throw `CancellationException`, and non-suspending loops need manual `isActive` checks.
Explain backpressure in Kotlin Flows and its management operators
This tests your understanding of Flow's pull-based nature and performance tuning. A great answer defines suspension as the default backpressure, then details how `buffer`, `conflate`, and `collectLatest` optimize it.
Explain Kotlin's declaration-site variance with `in` and `out`
This tests your grasp of type systems and API design. Explain how `out` (covariance/producer) and `in` (contravariance/consumer) provide type safety at the declaration site, simplifying usage. A red flag is confusing variance with immutability.
What is a CoroutineDispatcher and when do you use each type?
Tests your grasp of coroutine threading. A dispatcher manages which threads a coroutine runs on. Explain `Main` for UI, `Default` for CPU-intensive work, and `IO` for blocking operations. A red flag is mixing up `IO` and `Default` or using `Unconfined`.
Hot vs. Cold Streams: `StateFlow` vs. `Flow`
Tests your grasp of stream lifecycles. A great answer defines cold `Flow` (lazy, per-collector) vs. hot `StateFlow` (shared, active), then uses a ViewModel UI state scenario to show why `StateFlow` is correct for surviving configuration changes.
Structured Concurrency in Kotlin Coroutines
Tests your understanding of coroutine lifecycles and error handling. A good answer defines the parent-child relationship, then explains how cancellation and exceptions propagate through the scope. A red flag is simply calling it a way to 'group' coroutines.
Get Kotlin bites daily.
Five a day, five minutes, offline. With quizzes so it sticks.
Open testing — you’ll join as an early tester.