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.
Critical Insight
These 12 tactical fixes eliminated 80% of ANRs, from ditching SharedPreferences to streaming all file operations and avoiding service binders entirely.