Parse the Android ANR problem

1. Introduction to ANR

ANR is guaranteed by the message processing mechanism. Android implements a sophisticated mechanism to discover ANR at the system layer. The core principle is message scheduling and timeout processing. The main body of the ANR mechanism is implemented at the system layer. All messages related to ANR will be dispatched by the system process system_server, specifically the ActivityManagerService service, and then dispatched to the application process to complete the actual processing of the message. At the same time, the system process has designed different timeout limits to Trace the processing of messages. Once the application processes the message improperly, the timeout limit comes into play. It collects some system status, such as CPU/IO usage, process function call stack CallStack, (some platforms, such as MTK, will also print the corresponding Message for debugging and analysis) , and finally report to the user that the process is not responding (ANR dialog).

1.1, ANR type

There are generally three types of ANR:

1.1.1、KeyDispatchTimeout

This is mainly because the key or touch event does not respond within a certain period of time. Generally, the Android platform defaults to a timeout of 5s and anr will be reported, but some platforms will modify this time. For example, some platforms of MTK have a timeout of 8s.

This timeout can be viewed in ActivityManagerService.java:

おすすめ

転載: blog.csdn.net/wangqing830414/article/details/129355703