Android Learning: UI thread Blocking

Source: Internet
Author: User

One: Look at the program



Second: Phenomenon
when the program starts, Button1 will automatically swipe to the right three times, but when you click Button2, the Button1 move will pause for 5 seconds.

Three: Thread blocking:
When an application is launched, the Android system will create a main thread for the app. This thread is very important, it is responsible for rendering the view, distributing the event to the response listener and executing, polling the interface for listening. Therefore, it is generally called the "UI thread".
The Android system does not give the application multiple element components to build multiple threads to execute. Multiple view components in an activity are running in the same UI thread. As a result, the execution of listeners for multiple view components may affect each other.
For example, when you perform time-consuming operations in the UI thread, such as accessing the network, accessing the database, and so on. Will cause the UI thread to block. When the UI thread is blocked, the screen will appear stuck. This makes the user experience very poor. When the thread is blocked for more than 5 seconds, the Android system may intervene, and a popup dialog asks whether to close the application.

Android Learning: UI thread Blocking

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.