Android ANR trigger mechanism and log analysis

1.ANR

The Android system requires some events to be completed within a certain period of time. If no effective response is received within the predetermined time or the response time is too long, it will cause ANR (Application Not Responding).

There are 4 ANR occurrence scenarios in Android:

①Click event (button and touch event): The click event is not processed within 5s, and the log description is Input event dispatching timed out.

② Service Service: The foreground Service is not started within 20s and the background Service is not completed within 200s, and the log describes it as Timeout executing service.

③Broadcast BroadcastReceiver: within 10s of the foreground broadcast and 60s of the background broadcast, onReceive() is not processed within the specified time, and the log description is Timeout of broadcast Broadcast Record.

Note that the ANR time of the foreground broadcast is 10s before onReceive() is executed. This is only 10s if there is no click event that causes ANR. Otherwise, the ANR of the click event will be triggered first, and onReceive() may be executed. ANR occurs in less than 10s, so do not process time-consuming operations in onReceive().

④ Content Provider ContentProvider: The publish is not processed within 10s, and the log description is Timeout publishing content providers.

The triggering methods of these four ANRs are divided into two types: triggering ANR through the delay mechanism of the handler and triggering ANR by Input events. Among them, Service, BroadcastReceiver, and ContentProvider all trigger ANR through the Hander mechanism.

ANR generation needs to meet three conditions at the same time:

①Main thread: ANR will only be generated when the main thread of the application responds overtime;

② super

Guess you like

Origin blog.csdn.net/zenmela2011/article/details/128576128