Android Guides | Samples

Android.OS.Looper Class

Class used to run a message loop for a thread.

See Also: Looper

Syntax

[Android.Runtime.Register("android/os/Looper", DoNotGenerateAcw=true)]
public class Looper : Object

Remarks

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 Looper.Prepare in the thread that is to run the loop, and then Looper.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 Looper.Prepare and Looper.Loop to create an initial Handler to communicate with the Looper.

java Example

  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();
      }
  }

[Android Documentation]

Requirements

Namespace: Android.OS
Assembly: Mono.Android (in Mono.Android.dll)
Assembly Versions: 0.0.0.0
Since: Added in API level 1

The members of Android.OS.Looper are listed below.

See Also: Object

Protected Constructors

A constructor used when creating managed representations of JNI objects; called by the runtime.

Public Properties

[read-only]
static
MainLooperLooper. Returns the application's main looper, which lives in the main thread of the application.
[read-only]
ThreadThread. Gets the Thread associated with this Looper.

Protected Properties

[read-only]
override
ThresholdClassIntPtr. This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.
[read-only]
override
ThresholdTypeType. This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

Public Methods

Dump(IPrinter, String)
Dumps the state of the looper for debugging purposes.
static
Loop()
Run the message queue in this thread.
static
MyLooper() : Looper
Return the Looper object associated with the current thread.
static
MyQueue() : MessageQueue
Return the MessageQueue object associated with the current thread.
static
Prepare()
Initialize the current thread as a looper.
static
PrepareMainLooper()
Initialize the current thread as a looper, marking it as an application's main looper.
Quit()
Quits the looper.
QuitSafely()
Quits the looper safely.
SetMessageLogging(IPrinter)
Control logging of messages as they are processed by this Looper.