AceMobileInterview

Interview guides / android

Corrupt draft cache: Android Interview Question

Corrupt draft cache interview question with a clear example answer for Android engineers. Practice with AceMobileInterview.

This is a common Android interview topic: Corrupt draft cache.

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

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