java.lang.Object | |
↳ | android.os.Looper |
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(); } }
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Returns the application's main looper, which lives in the main thread of the application.
| |||||||||||
Return the Thread associated with this Looper.
| |||||||||||
Run the message queue in this thread.
| |||||||||||
Return the Looper object associated with the current thread.
| |||||||||||
Return the MessageQueue object associated with the current
thread.
| |||||||||||
Initialize the current thread as a looper.
| |||||||||||
Initialize the current thread as a looper, marking it as an application's main
looper.
| |||||||||||
Control logging of messages as they are processed by this Looper.
| |||||||||||
Returns a string containing a concise, human-readable description of this
object.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class java.lang.Object
|
Returns the application's main looper, which lives in the main thread of the application.
Return the Thread associated with this Looper.
Run the message queue in this thread. Be sure to call quit() to end the loop.
Return the Looper object associated with the current thread. Returns null if the calling thread is not associated with a Looper.
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.
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. prepare()
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.
printer | A Printer object that will receive log messages, or null to disable message logging. |
---|
Returns a string containing a concise, human-readable description of this object. Subclasses are encouraged to override this method and provide an implementation that takes into account the object's type and data. The default implementation simply concatenates the class name, the '@' sign and a hexadecimal representation of the object's hashCode(), that is, it is equivalent to the following expression:
getClass().getName() + '@' + Integer.toHexString(hashCode())