What is ANR? How to avoid and solve the ANR

Source: Internet
Author: User

On Android, if your application has been unresponsive for a while, the system will display a dialog box to the user
This dialog box is called the application unresponsive (anr:application not responding) dialog box. Users can choose to have
The program continues to run, but when they use your application, they do not want to process the dialog box every time. Therefore, the process
The design of the response performance is important so that the system does not show the ANR to the user.
Activity 5 Seconds broadcast10 seconds
Time consuming operation worker thread inside complete, handler message ... Asyntask, Intentservice, etc...
Anr:application not responding, i.e. application unresponsive
There are generally three types of ANR:
1:keydispatchtimeout (5 seconds)--main type
Key or touch events do not respond at a specific time
2:broadcasttimeout (seconds)
Broadcastreceiver cannot process completion at a specific time
3:servicetimeout (seconds)--Small probability type
Service cannot process completion at a specific time
There are two common reasons for timeouts:
(1) The current event does not have a chance to be processed (UI line is impersonating is not completed in time before processing or looper by some kind of original
Due to obstruction)
(2) The current event is being processed, but not completed in time
The UI thread tries to do only UI-related work, time-consuming work (database operations, I/O, network connectivity, or other possible impediments to the UI
thread) into a separate thread processing, using handler to handle the interaction between the UI thread and thread.
The UI thread mainly includes the following:
Activity:oncreate (), Onresume (), OnDestroy (), OnKeyDown (), OnClick ()
Asynctask:onpreexecute (), Onprogressupdate (), OnPostExecute (), OnCancel ()
Mainthread handler:handlemessage (), post (runnable R)
Ways to find ANR: 1. Export/data/data/anr/traces.txt, identify functions and call procedures, parse code 2. Pass
Performance Log human flesh search

What is ANR? How to avoid and solve the 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.