6 ways the UI thread interacts with background threads in Android

Source: Internet
Author: User

In the design idea of Android, in order to ensure the user smooth operation experience. Some time-consuming tasks cannot be run in the UI thread, such as accessing the network. So we have to re-open a background thread to run these tasks. However, these tasks often end up needing to access and control the UI controls directly or indirectly. For example, access to the network to obtain data, and then need to display these data processing. The above-mentioned situation arises. This is a normal phenomenon, but Android rules that no other thread can access and manipulate the UI controls other than the UI thread. In order to solve this problem, it leads to our topic today. How background threads in Android interact with the UI thread.

As far as I know, Android provides the following methods to enable background threads to interact with the UI thread.

1, Handler

2, Activity.runonuithread (Runnable)

3, View.post (Runnable)

4, view.postdelayed (Runnabe,long)

5, Asynctask

6, Broadcastreciver

6 ways that UI threads in Android interact with background threads design

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.