AsyncTask BASICS (notes)

Source: Internet
Author: User

AsyncTask BASICS (notes)

Android asynchronous task --- AsyncTask

Why asynchronous tasks:

1. Android single-threaded Model

2. Time-consuming operations are executed in non-main thread


Why is AsyncTask?

1. Update the UI in the Child thread

2. encapsulation to simplify asynchronous operations


Construct parameters of AsyncTask subclass

AsyncTask It is an abstract class that is generally used for inheritance. to inherit from AsyncTask, you must specify the following three generic parameters:

Params: the type of the input parameter when the task is started, that is, the input parameter in the execute () method.

Progress: the type of the returned Progress value during background task execution. It is used when the Progress is updated.

Result: The type of the returned Result after the backend executes the task. If the backend obtains an image from the network, the Bitmap type is returned.

Callback method for constructing AsyncTask subclass

(Insert knowledge: What is a callback function) when you go to a store to buy things, you just have no goods, so you left your phone number at the clerk, after a few days there will be goods in the store, the clerk will call you, and then you will get the goods in the store after receiving the call. In this example, your phone number is called a callback function. If you leave the phone number to the clerk, it is called a registration callback function. Later, the store purchased the event called triggering a callback Association, the clerk calls you to call the callback function. When you pick up the goods in the store, it is called a response callback event. (

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.