AceMobileInterview

Interview guides / android

Activity leak + token logs: Android Interview Question

Activity leak + token logs interview question with a clear example answer for Android engineers. Practice with AceMobileInterview.

This is a common Android interview topic: Activity leak + token logs.

Below is a concise answer you can adapt in a real interview, then go deeper in the full AceMobileInterview track.

  1. 1.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

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