Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags


What is ANR?

Educative Answers Team

ANR or Application Not Responding is an android error that happens when the UI thread becomes unresponsive to the user. When the application becomes unresponsive, the user is presented with an ANR dialog that gives them the option to force quit the application.

What triggers ANR?

  1. If your application does not respond to user input or BroadcastReceiver within five seconds.

  2. Your BroadcastReceiver has not finished executing within a considerable amount of time, and the application has no ongoing foreground task.

A foreground task is a task noticeable by the user. An example of an ongoing foreground task is a music application playing audio. These tasks display a notification to the user.

A **BroadcastReceiver is a component that listens to system-wide broadcasts such as a broadcast announcing that the screen was turned off.

Common culprits

Generally, ANRs are triggered because your application is doing the following:

  1. Performing slow operations with I/O on the main thread.
  2. Doing long calculations on the main thread.
  3. Performing a synchronous binder call in the main thread and the other process is taking time to respond.
  4. Waiting in the main thread for another thread that is performing a long operation.
  5. Stuck in a deadlock situation. Deadlocks can happen in the main thread when it is waiting on resources that another process has not released, so it cannot acquire the resources it needs. These other processes may be in another thread, your process, or in a binder call.

Diagnosis techniques

Use strict mode

With StrictMode you can find accidental I/O operations.

Read more about StrictMode in the official documentation.

Enable background ANR dialogs in developer options

Not all ANRs are visible to the user; therefore, the application may be facing performance issues without the user realizing. Enable background ANR dialogs in developer options.

Inspect trace files using adb

Trace files are generated in an ANR event. You can pull these files using Android Debug Bridge (adb) as root by using the following commands:

adb root
adb shell ls /data/anr
adb pull /data/anr/<filename>

Read the complete android documentation for ANRs here.


Copyright ©2022 Educative, Inc. All rights reserved

View all Courses

Keep Exploring