Methods Summary |
---|
public void | dump(android.util.Printer pw, java.lang.String prefix)
pw.println(prefix + this);
pw.println(prefix + "mRun=" + mRun);
pw.println(prefix + "mThread=" + mThread);
pw.println(prefix + "mQueue=" + ((mQueue != null) ? mQueue : "(null"));
if (mQueue != null) {
synchronized (mQueue) {
Message msg = mQueue.mMessages;
int n = 0;
while (msg != null) {
pw.println(prefix + " Message " + n + ": " + msg);
n++;
msg = msg.next;
}
pw.println(prefix + "(Total messages: " + n + ")");
}
}
|
public static final synchronized android.os.Looper | getMainLooper()Returns the application's main looper, which lives in the main thread of the application.
return mMainLooper;
|
public java.lang.Thread | getThread()Return the Thread associated with this Looper.
return mThread;
|
public static final void | loop()Run the message queue in this thread. Be sure to call
{@link #quit()} to end the loop.
Looper me = myLooper();
MessageQueue queue = me.mQueue;
while (true) {
Message msg = queue.next(); // might block
//if (!me.mRun) {
// break;
//}
if (msg != null) {
if (msg.target == null) {
// No target is a magic identifier for the quit message.
return;
}
if (me.mLogging!= null) me.mLogging.println(
">>>>> Dispatching to " + msg.target + " "
+ msg.callback + ": " + msg.what
);
msg.target.dispatchMessage(msg);
if (me.mLogging!= null) me.mLogging.println(
"<<<<< Finished to " + msg.target + " "
+ msg.callback);
msg.recycle();
}
}
|
public static final android.os.Looper | myLooper()Return the Looper object associated with the current thread. Returns
null if the calling thread is not associated with a Looper.
return (Looper)sThreadLocal.get();
|
public static final MessageQueue | myQueue()Return the {@link MessageQueue} object associated with the current
thread. This must be called from a thread running a Looper, or a
NullPointerException will be thrown.
return myLooper().mQueue;
|
public static final 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
{@link #loop()} after calling this method, and end it by calling
{@link #quit()}.
if (sThreadLocal.get() != null) {
throw new RuntimeException("Only one Looper may be created per thread");
}
sThreadLocal.set(new Looper());
|
public static final void | prepareMainLooper()Initialize the current thread as a looper, marking it as an application's main
looper. The main looper for your application is created by the Android environment,
so you should never need to call this function yourself.
{@link #prepare()}
prepare();
setMainLooper(myLooper());
if (Process.supportsProcesses()) {
myLooper().mQueue.mQuitAllowed = false;
}
|
public void | quit()
Message msg = Message.obtain();
// NOTE: By enqueueing directly into the message queue, the
// message is left with a null target. This is how we know it is
// a quit message.
mQueue.enqueueMessage(msg, 0);
|
private static synchronized void | setMainLooper(android.os.Looper looper)
mMainLooper = looper;
|
public void | setMessageLogging(android.util.Printer printer)Control logging of messages as they are processed by this Looper. If
enabled, a log message will be written to printer
at the beginning and ending of each message dispatch, identifying the
target Handler and message contents.
mLogging = printer;
|
public java.lang.String | toString()
return "Looper{"
+ Integer.toHexString(System.identityHashCode(this))
+ "}";
|