1 Try {2 Thread.Sleep (+); 3 Catch (interruptedexception e) {4 e.printstacktrace (); 5 }6 method2:SystemClock.sleep (+);
ANR (application not responding) on Android, if the application has been unresponsive for some time, a dialog box is displayed to the user called the application is unresponsive (anr:application not Responding) dialog box. The user can select wait to keep the program running, or force close. So a smooth and reasonable application can not appear in the ANR, and let the user each time to deal with this dialog box. Therefore, it is important to design the response performance in the program so that the system does not show the ANR to the user. Causes of ANR The maximum execution time for activity in Android is 5 seconds by default, and the maximum execution time for Broadcastreceiver is 10 seconds. Exceeding will prompt the application to be unresponsive (anr:application not responding) dialog box. Three common types
1: keydispatchtimeout (5 seconds)-- Main Types
(no response within main thread of activity within 5s) key or touch events are unresponsive at specific times
2 : broadcasttimeout (seconds)
(Broadcastreceiver 10s) Broadcastreceiver cannot process completion at a specific time
3: servicetimeout (seconds)-- Small probability type
(Service 20s) Service cannot process completion at a specific time
Service running in the main thread, can not do time-consuming operation, will lead to ANR (20s), if need to do time-consuming operation in the service, need to open child thread
Two kinds of sleep methods for thread &ANR (process/service unresponsive)