It is based on the user interface thread and how long it takes for the user interface thread to return to the message loop (the message loop is hidden from you as the application developer, but there is a giant loop in the user interface thread that accepts messages for user input, drawing requests, completion AsyncTask etc.). Basically, you have a fixed amount of time per message before it announces ANR. Time spent sleeping waiting for a message will never call ANR. Android has a separate watchdog process that checks how much time has passed since the last thread hit the top of this loop, and if it kills it for too long and displays the ANR dialog.
source share