Mr.AndroidShin / Dev Tools

Debugging log · Performance

ANR — "Application Not Responding"

Users started seeing the dreaded Application Not Responding dialog — the one that offers to close the app — and Play Console's Android vitals lit up with an ANR rate. There was no crash, no exception, no stack trace in the usual sense. The app wasn't broken; it was busy. The main thread sat blocked long enough that the system decided the app had hung.

The short version: an ANR fires when the main (UI) thread is blocked too long — roughly 5 seconds for an unhandled input event. Something slow is running where it shouldn't: disk, network, a big loop, or a lock. Read the ANR trace to find what the main thread was doing, and move that work off it.

What triggers an ANR

Android watches the main thread because that thread draws the UI and handles taps. If it can't respond to an input event within about 5 seconds — or finish a BroadcastReceiver or Service lifecycle step within its own limit — the system raises an ANR. The cause is always the same shape: something that should have run in the background ran on the main thread and held it. Unlike a crash, there's no exception thrown; the symptom is a freeze, so you have to look at what the main thread was stuck on.

Read the ANR trace

An ANR produces a trace (in Play Console's Android vitals, or on-device under /data/anr/, or via adb bugreport). Find the "main" thread in it and read its stack — the top frames show exactly what it was doing when it stalled. You're looking for one of a few tell-tales:

Fix: move the slow work off the main thread

Whatever the trace names, the fix is to run it in the background and only touch the UI when done. With coroutines:

lifecycleScope.launch {
    val result = withContext(Dispatchers.IO) {
        loadFromDatabase()   // the slow thing, off main
    }
    render(result)           // back on main
}

For CPU-heavy work use Dispatchers.Default; for disk/network use Dispatchers.IO. The principle is identical to avoiding the main-thread network and wrong-thread view crashes — keep the UI thread free to respond.

Specific offenders worth hunting

An ANR isn't a bug with a line number — it's a budget you blew. Treat the 5-second window as a hard ceiling you should never come near: anything that might be slow (I/O, parsing, big loops) belongs off the main thread by default, not just when it happens to cross the line on a fast device.

Catching it before users do

Method names above are illustrative — use your own, and act on what your ANR trace's main thread is actually doing.