How to use Android Async tasks

Source: Internet
Author: User

Many of the actions above Android cannot be placed directly on the UI thread. When the UI thread is blocked for more than 5 seconds, the application will have an unresponsive dialog box. When this phenomenon occurs, it will directly affect the user experience. So we need to handle the asynchronous task or operation by means of the method. Here is a list of centralized and related processing methods:

First of all, we should think of using Thread+handler to implement a non-UI thread to update the UI interface, that is, when threads execute by sending a message to process and update the UI through handler. Another way is through the asynchronous task: Asynctask to the data processing, by inheriting Asynctask and rewriting the related methods, the more important is dobackground and Onpostexecutor rewrite. One is responsible for handling transactions, one is responsible for updating the interface.

Basically the first thing we think about is that these two methods are mentioned above, in fact there are two methods, one is through the service, the other is through the intentservice to deal with.


This article is from the "Android Learning Archive" blog, so be sure to keep this source http://renhui.blog.51cto.com/8943504/1536122

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.