ANR are one of the biggest nightmares of every Android Developer. ANR means Application Not Responding and it is exactly this. There are three main types of ANR:
- The app is doing slow I/O operations on the main thread.
- The app performs long calculations on the main thread.
- The main thread waits for a synchronous block for a long operation that is performing on an another thread.
So we also have three main ways to diagnose what is going on when we have ANR. There it goes:
- Strict mode – used to intercept I/O operations performed on the main thread of the application (e.g. disk or network access). Check here how to use it https://www.htc.com/ca/contact/productissue/htc/GUID-3C5CBA55-FEF8-45A2-8BDB-3702DF41A8BA/
- Traceview – allows you to identify where the main thread is busy. It is one of the functionalities of the Android Device Monitor. And more info about it here: https://developer.android.com/studio/profile/traceview
- Extract the traces of the „ANR” error – these traces are saved in the text files of the device. You can access them using the Android Debug Bridge. Very helpful link here: https://developer.android.com/studio/debug/bug-report
Let me know if you use those methods, or have any other ideas how to deal with ANR as an Android Developer.