(Android practice) asynctask and handler asynchronous implementation principles and advantages and disadvantages comparison

Source: Internet
Author: User

1 asynctaskImplementation principle,Applicable advantages and disadvantages

Asynctask is a lightweight asynchronous class provided by Android. It can inherit asynctask directly and implement asynchronous operations in the class,AndProvide interface feedback to the currentAsynchronous execution degree(Ui progress update can be implemented through the interface), and finally the execution result is fed back to the main UI thread.

Advantages:

L simple and fast

L process controllable

Disadvantages:

L it becomes complicated when multiple asynchronous operations and UI changes are required.

2 HandlerPrinciples and advantages of asynchronous implementation

When handler is implemented asynchronously, it involves four objects: handler, logoff, message, and thread. the asynchronous process is that the main thread starts thread (subthread) à thread (subthread) run and generate message-à logoff to get the message and pass it to handler. the handler gets the message in logoff one by one and changes the UI.

Advantages:

L clear structure and clear Function Definition

L simple and clear for multiple background tasks

Disadvantages:

L when asynchronous processing is performed on a single backendCodeToo many, too complex structure (relative)

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.