Android ANR and androidANR

Source: Internet
Author: User

Android ANR and androidANR
There are three types of ANR:
1:KeyDispatchTimeout (5 seconds)
Buttons or touch events do not respond within a specific period of time
2: BroadcastTimeout (10 seconds)
BroadcastReceiver cannot be processed within a specific period of time
3:ServiceTimeout (20 seconds)

Service cannot be processed within a specified period of time



KeyDispatchTimeout
Akey or touch event was not dispatched within the specified time (the key or touch event does not respond within a specific time period)
The specific time-out period is defined in
ActivityManagerService. java
// How long we wait until we timeout on key dispatching.
Staticfinal int KEY_DISPATCHING_TIMEOUT = 5*1000
The timeout period generally starts when the keys are distributed to the app. There are two common causes of Timeout::
(1) The current event has no chance to be processed (that is, the UI thread is processing the previous event and is not completed in time or the logoff is blocked for some reason)
(2) The current event is being processed, but it is not completed in time
How to avoidKeyDispatchTimeout
1: The UI thread should only do work related to the UI as much as possible.
2: time-consuming work (such as database operations, I/O, network connections, or other operations that may hinder the UI thread) Put it into a separate thread for processing
3: Use Handler to handle the interaction between UIthread and other threads.

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.