Search code examples
androidandroid-anr-dialogandroid-background

How to avoid ANR From an app when it is not in the foreground?


I am trying to find a solution for Application Not Responding (ANR) error when my app is in background. I want any ANR not to occur when my app is not in foreground. How this can be achieved? Thanks in advance.


Solution

  • From Google docs:

    Android will display the ANR dialog for a particular application when it detects one of the following conditions:

    • No response to an input event (such as key press or screen touch events) within 5 seconds.
    • A BroadcastReceiver hasn't finished executing within 10 seconds.

    After that be sure to not do blocking/long operations on the UiThread/MainThread even if the App is in background.