Android Chinese API (128) -- HandlerThread

Source: Internet
Author: User

 

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.