Looper objects in Android are described in detail _android

Source: Internet
Author: User

Java Official website Description of the Looper object:


public class Looperextends Object
Class used to run a message loop for a thread. Threads By default don't have a message loop associated with them; To create one, call prepare () in the thread, the "is" to run the loop, and then loop () to have it process messages until the The loop is stopped.

Most interaction with a message loop is through the Handler class.

This is a typical example of the implementation of a looper thread, using the separation of prepare () and loop () to create An initial Handler to communicate with the Looper.

Copy Code code as follows:

Class Looperthread extends Thread {
Public Handler Mhandler;

public void Run () {
Looper.prepare ();

Mhandler = new Handler () {
public void Handlemessage (msg) {
Process incoming messages here
}
};

Looper.loop ();
}
}

Main methods:

The

static void Loop ():  Run the message queue in this thread. The
static void prepare ():  Initialize The current thread as a looper.

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.