public class

Looper

extends Object
java.lang.Object
   ↳ mindroid.os.Looper

Class Overview

Class used to run a message loop for a thread. Threads by default do not have a message loop associated with them; to create one, call prepare() in the thread that is to run the loop, and then loop() to have it process messages until 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.

  class LooperThread extends Thread {
      public Handler mHandler;

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

          mHandler = new Handler() {
              public void handleMessage(Message msg) {
                  // process incoming messages here
              }
          };

          Looper.loop();
      }
  }
 

Summary

Public Methods
Thread getThread()
Return the Thread associated with this Looper.
boolean isCurrentThread()
Returns true if the current thread is this looper's thread.
static void loop()
Run the message queue in this thread.
static Looper myLooper()
Return the Looper object associated with the current thread.
static MessageQueue myQueue()
Return the MessageQueue object associated with the current thread.
static void prepare()
Initialize the current thread as a looper.
void quit()
Quits the looper.
String toString()
[Expand]
Inherited Methods
From class java.lang.Object

Public Methods

public Thread getThread ()

Return the Thread associated with this Looper.

public boolean isCurrentThread ()

Returns true if the current thread is this looper's thread.

public static void loop ()

Run the message queue in this thread. Be sure to call quit() to end the loop.

public static Looper myLooper ()

Return the Looper object associated with the current thread. Returns null if the calling thread is not associated with a Looper.

public static MessageQueue myQueue ()

Return the MessageQueue object associated with the current thread. This must be called from a thread running a Looper, or a NullPointerException will be thrown.

public static void prepare ()

Initialize the current thread as a looper. This gives you a chance to create handlers that then reference this looper, before actually starting the loop. Be sure to call loop() after calling this method, and end it by calling quit().

public void quit ()

Quits the looper. Causes the loop() method to terminate as soon as possible.

public String toString ()