Preface
This chapter is about android. OS. HandlerThread. The version is Android 3.1 r1 and translated from "xueying Studio". Thanks again "xueying Studio "! Welcome to join in Android Chinese translation, contact me over140@gmail.com.
Statement
You are welcome to repost, but please keep the original source of the article :)
Blog Garden: http://www.cnblogs.com/
Android Chinese translation group: http://goo.gl/6vJQl
HandlerThread
Translator's signature: xueying Studio
Version: Android 3.1 r1
Structure
Inheritance relationship
Public class HandleThread extends Thread
Java. lang. Object
Java. lang. Thread
Android. OS. HandlerThread
Class Overview
It is used to easily create a Thread class containing logoff. Logoff is used to create the handler class. Note that you still need to call the start () method.
Constructor
Public HandlerThread (String name)
Construct a HandlerThread
PublicHandlerThread(String name, int priority)
Construct a HandlerThread
Parameters
Priority indicates the priority of the running Thread. This value is provided by Android. OS. Process rather than from java. lang. Thread.
Common Methods
Public LogoffGetLooper()
This method returns the logoff related to this thread. If the thread cannot be started or the isAlive () method returns false for some reason, the method returns null. If the thread has been started, this method will be blocked until logoff is initialized.
Return Value
Logoff
Public intGetThreadId()
The flag of the returned thread. For details, see Process. myTid ()
Public booleanQuit()
Check whether the currently running logoff has exited. If the thread is not started or has ended (that is, the getlogoff () method returns null), this method returns false. Otherwise, logoff is required and true is returned.
Public voidRun()
Call the run () method of the Runnable object. If Runnable is not set, do nothing.
Protected Methods
Protected voidOnLooperPrepared()
If you need to execute some settings before the logoff loop, you can explicitly inherit the callback method.
(Translator's note: The following code:
Void run (){
MTid = Process. myTid ();
Lomap. prepare (); // create a lomap instance and store it in ThreadLocal. Maintain a HashMap in ThreadLocal and the key is the thread number.
Synchronized (this ){
Mlo = Looper. myLooper (); // obtain the Looper of the current thread, that is, the Looper instance created and stored in the perpare method.
Process. setThreadPriority (mPriority );
Policyall ();
}
OnLooperPrepared ();
Logoff. loop (); // start round robin
MTid =-1;
)
Supplement
Article Selection
Android development-handler (2)
AsyncQueryHandler
For details about Thread, logoff, Handler, and Message, see [Android123]
Relationship between android Thread HandlerThread low.message MessageQueue Handler