When an Android app shows the dreaded App Not Responding (ANR) dialog, the device feels frozen and you’re left wondering what went wrong. This guide walks you through a repeatable workflow to capture the exact cause, interpret the information, and apply concrete fixes – all without rooting the phone.
Build number seven times).An ANR is triggered when the main (UI) thread of an app is blocked for more than five seconds. Android’s watchdog watches three key queues:
If any of those queues exceed the timeout, the system shows the ANR dialog. The good news is that the exact cause is always recorded in system logs, which we can retrieve with ADB.
Goal: obtain the raw log that contains the ANR trace.
adb devices
You should see a line with your device’s serial number.
adb logcat -b events -v time "*:*" | grep -i "ANR" > anr_log.txt
Leave this terminal window open; it will continue to write to anr_log.txt until you stop it (Ctrl +C).
adb shell dumpsys activity > activity_dump.txt
This creates activity_dump.txt with the full activity manager state, including the ANR trace.
Open activity_dump.txt in any text editor and search for the string ANR in. You’ll see a block similar to:
ANR in com.example.myapp (com.example.myapp/.MainActivity)
Reason: Input dispatching timed out (Waiting for event dispatch)
KeyDispatchingTimedOut: keyDispatchingTimedOut
at android.view.ViewRootImpl$W@... (some stack)
at android.os.Handler.handleCallback(Handler.java:...)
...
The first line tells you which package is at fault. The Reason line explains which queue timed out. The following stack trace shows the exact Java call stack that was stuck.
Read the stack trace carefully; the topmost method (the first line after the exception) is where the UI thread was busy.
Typical stack entries:
at com.example.myapp.network.ApiClient.fetchData(ApiClient.java:45)
at com.example.myapp.ui.MainActivity.onCreate(MainActivity.java:30)
**Why it matters:** Network calls, large database queries, or file I/O on the UI thread block the event queue.
Fixes:
AsyncTask (legacy), WorkManager, ExecutorService, or Kotlin coroutines with Dispatchers.IO.BroadcastReceiverStack example:
at com.example.myapp.receiver.SyncReceiver.onReceive(SyncReceiver.java:22)
**Why it matters:** The system expects onReceive() to finish quickly (under 10 ms). Doing heavy work here triggers an ANR.
Fixes:
goAsync() and start a background service or JobIntentService to finish the work.WorkManager directly from the receiver.ContentProvider queriesStack example:
at android.content.ContentResolver.query(ContentResolver.java:1234)
at com.example.myapp.data.ContactRepository.loadAll(ContactRepository.java:57)
**Fix:** Perform the query on a background thread (e.g., via LiveData + Room or coroutines).
Even a Service that does not have its own thread runs on the UI thread by default.
**Fix:** Convert the service to an IntentService (deprecated) or better, use JobIntentService / WorkManager for background work.
Very deep view hierarchies or complex custom drawing can cause the UI thread to spend >5 s measuring/layout.
**Fix:** Use ConstraintLayout, flatten the hierarchy, and profile with Android Studio’s Layout Inspector.
If you have the source code, the most visual way to confirm that the UI thread is no longer blocked is the CPU profiler.
main thread. The call stack should now show only quick UI work.If the spike disappears, you’ve likely resolved the root cause.
Sometimes you’re dealing with a third‑party app and can’t change the code. Try these system‑level actions:
If multiple apps are showing ANR dialogs, the problem is likely device‑wide:
adb devices:
adb access on macOS/Linux.grep filter to verify logging works.adb logcat -v time instead.activity_dump.txt:
dumpsys activity command *while* the ANR dialog is visible.adb shell am dumpheap to capture a heap dump for deeper analysis.activity_dump.txt and/or filtered logcat during the ANR.Reason line.activity_dump.txt section and mention the Android version and device model. This gives them a precise starting point.With the steps above you should be able to turn a frustrating ANR dialog into a clear, solvable problem. Whether you’re a hobbyist developer tweaking your own app or a power user trying to keep third‑party apps stable, the same workflow applies – capture, analyze, fix, and verify.









