AceMobileInterview

Interview guides / android

Android Debugging Interview Questions

Android debugging interview questions on ANRs, jank, crashes, race conditions, and practical investigation workflows.

Android debugging interviews reward structured investigation: reproduce, read traces, form hypotheses, patch, and prove the fix.

Practice on real buggy projects when you can. AceMobileInterview ships planted ANR/jank/crash exercises for Android Studio.

  1. 1.How do you diagnose an ANR?

    Read the ANR trace for the main thread stack, find blocking disk/network/lock work, move it off Main, and add safeguards. Reproduce with large inputs and strict mode where helpful.

  2. 2.Compose list janks when opening a screen with a big payload. What next?

    Check work during composition, unstable keys, main-thread parsing, and image work. Profile, hoist state, stabilize keys, and move heavy work to background before updating UI state.

  3. 3.Swipe-delete sometimes crashes detail navigation. How do you reason about it?

    Suspect index/identity mismatches after list mutation, stale navigation args, or null unchecked models. Prefer stable IDs over positions and guard navigation targets.

  4. 4.Download the buggy Android zip. Opening the list with a large payload janks the UI. Find wrong-thread work and fix it (≈45–60 min).

    ## Scenario Compose/list screen freezes while parsing a large bundled JSON feed. ## How to investigate - Reproduce on launch with `assets/feed.json` - Android Studio CPU Profiler / Systrace - Search for `readText` / `Json.decodeFromString` on the main path ## Planted bug 1: Parse on Main **Symptom:** Frame freeze on first frame **Root cause:** Repository reads assets and decodes on `Dispatchers.Main` (or callers use `runBlocking` on main) **Fix:** `withContext(Dispatchers.Default)` for parse; `Dispatchers.IO` for asset read ## Planted bug 2: Bitmap work on UI thread **Symptom:** Scroll jank **Root cause:** `BitmapFactory.decodeByteArray` inside item composable / bind **Fix:** Decode on background; cache; use a proper image loader as stretch ## Planted bug 3: Architecture smell **Symptom:** Hard to test **Root cause:** Activity/ViewModel reaches into assets directly **Fix:** `FeedRepository` interface; inject fake in tests ## Optimization tips - Never `runBlocking` from a Composable - Prefer `StateFlow` updates after background work completes ## What to say in the interview - How you proved main-thread work before refactoring - What metric you re-checked after (time-to-content, jank frames)

  5. 5.Swipe-delete or empty list can crash detail navigation. Fix unsafe indexes/nulls (≈30–45 min).

    ## Scenario List/detail crashes after delete and when empty. ## How to investigate - Exception breakpoint / Logcat stack - Delete last item; tap quickly during animation - Find `list[index]` and `!!` ## Planted bug 1: Stale index click **Symptom:** `IndexOutOfBoundsException` **Root cause:** Click listener captures index; list mutates before navigation **Fix:** Pass item `id`; look up in the current snapshot ## Planted bug 2: Unsafe `!!` on args **Symptom:** NPE when args missing **Root cause:** `requireArguments().getString("id")!!` **Fix:** Null-check; pop back; show empty state ## Planted bug 3: Empty list assumption **Symptom:** Crash in header/binder **Root cause:** Code assumes `items.first()` **Fix:** Guard empty; proper empty UI ## Optimization tips - Prefer immutable list snapshots in UI state - Key LazyColumn items by id ## What to say in the interview - How the stack pointed to the listener capture - Regression cases you’d add

  6. 6.Profile visits leak the Activity; Logcat prints the session token. Fix leaks and unsafe logging (≈30–45 min).

    ## Scenario Leaky Profile screen + secret in logs. ## How to investigate - LeakCanary or Profiler heap dump - Confirm Activity instance count after repeat visits - Grep `Log.` for token ## Planted bug 1: Static Activity reference **Symptom:** Activity retained after finish **Root cause:** `companion object { var host: Activity? }` set in `onCreate` never cleared **Fix:** Remove static; use application context only where safe; clear in `onDestroy` ## Planted bug 2: Uncancelled coroutine / listener **Symptom:** Callback touches dead UI **Root cause:** `GlobalScope.launch` or listener registered without removal **Fix:** `lifecycleScope` / `viewModelScope`; unregister listeners ## Planted bug 3: Logging secrets **Symptom:** Token in Logcat **Root cause:** `Log.d("Auth", token)` **Fix:** Delete; redact if absolutely needed ## Optimization tips - Treat Logcat as public on shared devices / bug reports - Prefer ViewModel for async that outlives rotation ## What to say in the interview - How you confirmed the leak root in the dump - Why `GlobalScope` is a red flag

  7. 7.MainActivity mixes networking, parsing, prefs, and UI with a hardcoded API key. Refactor the worst smells (≈45–60 min).

    ## Scenario God Activity with a committed secret. ## How to investigate - Skim `MainActivity.kt` responsibilities - Grep for API keys - Find main-thread `FileOutputStream` / prefs heavy writes ## Planted bug 1: Hardcoded API key **Symptom:** Secret in repo **Root cause:** `const val API_KEY = "sk_live_..."` **Fix:** BuildConfig / local properties placeholder; stub in exercise ## Planted bug 2: God object **Symptom:** Untestable **Root cause:** OkHttp + JSON + SharedPreferences + UI in Activity **Fix:** Extract `SettingsRepository` + ViewModel; Activity/Compose only collects state ## Planted bug 3: Main-thread disk write **Symptom:** Hitch on Save **Root cause:** Synchronous write on click handler **Fix:** `Dispatchers.IO`; then toast on Main ## Optimization tips - Interview success = clear boundaries, not perfect DI graph - Mention how you’d unit test the repository ## What to say in the interview - Secret removal first - What you deferred on purpose

  8. 8.Double-tapping Pay charges twice; cart state races. Fix concurrency (≈45–60 min).

    ## Scenario Checkout isn’t single-flight; shared cart mutates unsafely. ## How to investigate - Double-tap Pay with delay in fake API - Watch duplicate requests in Logcat - Trace `Cart.items` mutations ## Planted bug 1: No in-flight guard **Symptom:** Two checkout calls **Root cause:** Button stays enabled; ViewModel method re-entrant **Fix:** `if (isCheckingOut) return`; disable button; use `Mutex` or atomic flag ## Planted bug 2: Unsynchronized mutable list **Symptom:** Wrong totals / rare CME **Root cause:** `MutableList` edited from IO + Main **Fix:** Confine to Main; or `Mutex`; expose immutable snapshots via StateFlow ## Planted bug 3: UI update off main **Symptom:** Occasional threading issues **Root cause:** Updating LiveData/state from wrong context inconsistently **Fix:** Always emit UI state on Main ## Optimization tips - Mention server idempotency keys as the real backstop - `callbackFlow` / structured concurrency over ad-hoc threads ## What to say in the interview - UI disable vs true idempotency - How you’d write a stress test

  9. 9.Drafts vanish after process death; truncated JSON can crash on read. Fix atomicity and races (≈45–60 min).

    ## Scenario Draft JSON store is unsafe under kill + concurrent writes. ## How to investigate - Save rapidly while editing; force-stop app - Inspect filesDir draft file - Find `writeText` to final path + `!!` decode ## Planted bug 1: Non-atomic write **Symptom:** Truncated JSON **Root cause:** Direct write to destination **Fix:** Write temp + `renameTo` / `AtomicFile` ## Planted bug 2: Crash on bad JSON **Symptom:** Startup crash loop **Root cause:** Unchecked decode **Fix:** Catch; return empty draft; delete/quarantine bad file ## Planted bug 3: Concurrent read/write **Symptom:** Intermittent corruption **Root cause:** No mutex / single-thread executor around file access **Fix:** `Mutex` or single-thread dispatcher; debounce saves ## Optimization tips - `DataStore` is a strong modern answer—still explain atomicity underneath - Process death is normal; design for it ## What to say in the interview - How you reproduced partial writes - Why rename/AtomicFile matters

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.

iOS trackAndroid trackMore guides