I achieved 0% ANR in my Android app. Spilling beans on how I did it - part 1.
Article Summary
After a year of relentless optimization, one Android dev achieved the impossible: 0% ANR rate in production. Here's how they did it.
The Respawn team documented their journey to eliminate Application Not Responding errors completely. This first part covers 12 foundational fixes that eliminated 80% of their ANRs, with more advanced techniques promised in part two.
Key Takeaways
- SharedPreferences (especially encrypted) are the #1 ANR culprit. Switch to DataStore instead.
- 80% of ANRs came from memory leaks causing massive GC pauses during long sessions.
- Stack traces lie: 90% of ANRs are your code, not system calls.
- Enable StrictMode in content providers at MAX_VALUE priority, not Application.onCreate().
- Every OOM error can manifest as an ANR instead of a crash.
These 12 tactical fixes eliminated 80% of ANRs, from ditching SharedPreferences to streaming all file operations and avoiding service binders entirely.
About This Article
When bitmap and drawable files aren't organized properly, missing drawable-nodpi configurations cause the app to load oversized images. This drains memory and triggers ANRs instead of crashes, so the performance issues stay hidden.
Set up drawable resources correctly using drawable-nodpi folders. Profile how bitmaps are being used to stop large images from loading on the main thread.
Better bitmap memory management cut down on mysterious ANRs during long user sessions. The Respawn app reached near-zero ANR rates in production as a result.