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. (