Android Simple development tutorial 19: Thread Bézier curves

Source: Internet
Author: User
Tags java se

The method used for thread threading in Android is the same as the Java SE. Like most OS systems, Android also has a main thread called UI thread. UI Thread is primarily used to distribute messages to the appropriate widget, including drawing (Drawing) events. UI thread is also the thread used to handle user interaction events. For example, if you press a button on the screen, the UI thread notifies the corresponding control (Widgets) of the touch event, and the Widget sets its status to "down" and sends the "redraw" (Invalidate) incident to the event queue. The UI thread notifies widgets to redraw itself after reading events from the event queue.

If your application is poorly designed, this single-threaded mode of the UI thread can result in very poor user response performance. Especially if you put some time-consuming operations such as network access or database access on the UI thread, which can cause the user interface to be unresponsive, and worst of all, if the UI thread blocks for more than a few seconds (5 seconds), the famous ANR dialog box appears:

So when designing an application, you need to run some time-consuming tasks using a separate work thread to avoid blocking the UI thread, but if you want to update the UI thread in the worker thread, you cannot update the UI directly in the worker thread because the UI thread is not "thread Safe." Therefore, all UI-related operations typically have to be done in UI thread.

The Android OS provides several ways to access the UI thread with a non-UI thread.

Activity.runonuithread (Runnable)

View.post (Runnable)

View.postdelayed (Runnable, long)

Handler

Related Article

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.