How to diagnose ANR

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:

  1. The app is doing slow I/O operations on the main thread.
  2. The app performs long calculations on the main thread.
  3. 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:

  1. 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/
  2. 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
  3. 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.

Dodaj komentarz

Twój adres e-mail nie zostanie opublikowany. Wymagane pola są oznaczone *