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