Asynchronous processing in Android

Source: Internet
Author: User

The main message,handler,messagequeue,loop are:

1.Message and handler with:

Message message = new Message (); message.what = update_text;handler.sendmessage (message); Send the Message object out

  

Private Handler Handler = new Handler () {public void Handlemessage (Message msg) {switch (msg.what) {case update_text://in this UI Operation Text.settext ("Nice to Meet You"); break;default:break;}};

Message all the Members have

public int Arg1 Arg1 and Arg2 is lower-cost alternatives to the using if you only setData() need to store a few integer values.
public int Arg2 Arg1 and Arg2 is lower-cost alternatives to the using if you only setData() need to store a few integer values.
Public Object Obj An arbitrary object to send to the recipient.
Public Messenger ReplyTo Optional Messenger where replies to the message can be sent.
public int What User-defined message code So, the recipient can identify what's this message was about.

A message is an information that is passed between threads, which can carry a small amount of info inside a line
Exchange data between processes. In the previous section, we used the What field of the Message, in addition to making
Use the Arg1 and Arg2 fields to carry some integer data, using the Obj field to carry a single Object object.
To bring more data, you can use SetData (Bundle).

2 Handler

Handler, as the name implies, is the meaning of the processor, which is primarily used to send and process messages. Send and Cancel
The Handler SendMessage () method is used, and the messages sent are processed in a series of
Will eventually be passed to Handler's Handlemessage () method.
3 MessageQueue

MessageQueue is the meaning of Message Queuing, which is primarily used to store all messages sent through Handler.
This part of the message will remain in the message queue and wait for it to be processed. There will only be one MessageQueue in each thread
Object.
4 Loop

Looper is the steward of MessageQueue in each thread, and after calling the Looper loop () method, it
into an infinite loop, and then whenever a message is found in the MessageQueue, it is taken
and passed to the Handler handlemessage () method. There will only be one Looper object in each thread.

Asynchronous processing in Android

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.