Two sleep methods for thread &ANR (process/Service not responding)

Source: Internet
Author: User

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)

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.