ANR Trigger principle (what triggers ANR?)

Source: Internet
Author: User

REF:

Http://developer.android.com/training/articles/perf-anr.html

Http://stackoverflow.com/questions/3467205/android-key-dispatching-timed-out

http://blog.csdn.net/wuhengde/article/details/8007448

Google develop official online on the ANR trigger mechanism is described as follows: here from the source angle analysis of how AMS and WMS Monitor ANR. Android version: Android 5.0 Analysis object: monitor mechanism of keydispatchingtimedout  1. Keydispatchingtimedout (here ' key ' is not accurate, in fact inputevent (including KeyEvent and touchevent) distribution timeout, the current touch screen mobile phone, touchevent/motionevent-based ), first look at this block of Class diagram: You can see the real work is on the native side, by the native side monitor event is timed out, and trigger call Java side NOTIFYANR logic. The approximate timing of the ANR Monitor is as follows: The ANR Monitor core work is completed by InputDispatcher.cpp, and each time the event is dispatched, the following judgment is required: 1. Determine if there are focused components and focusedApplication2. Determine whether the previous event is completed in time for 1, generally at startup may trigger, such as the boot time is too long, in the process of triggering keyevent or trackball motionevent, the following logical judgment:

In this case, the corresponding ANR log is as follows:

Reason:input dispatching timed out (waiting because no window have focus but there is a focused application the May event ually Add a window when it finishes starting up.)

For 2,keyevent and motionevent on "timeliness" strategy, keyevent need to determine whether the previous event was completed (due to focus issues, keyevent must wait for the WMS to process the previous event before the new event is dispatched) : Checkwindowreadyformoreinputlocked and TouchEvent (touch screen, e.g.), you need to determine if the event waiting queue head event time has elapsed 0.5 seconds, relatively speaking, the touchevent requirements are lower, allowing greater execution latency, at this point, the UI thread is stuck, a bunch of touch event is waiting to be executed, Need to stop event delivery, so either keyevent (entity key input) or touchevent (click View) is the result of the UI thread not processing the previous event in time.Set the start and timeout values of the ANR, wake up the event at timeout, and then determine if the event is delivery by the above conditions, and if the conditions are met, you can go through the normal dispatch process, otherwise (such as the UI thread stuck, the UI thread can't get the CPU, etc.), The onanrlocked is triggered, and subsequent processes are shown in the sequence diagram.

ANR Trigger principle (what triggers ANR?)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.