Android英文文档翻译系列(2)——HandlerThread

本文介绍了一个便捷的类——HandlerThread,该类用于启动带有Looper的新线程,并可通过Looper创建Handler类。文章详细解释了HandlerThread的构造方法、如何获取Looper及线程ID、请求Looper退出的方法等关键知识点。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 
public class
 
HandlerThread
extends Thread
 
Class  Overview
Handy class for starting a new thread that has a looper.The looper can than be used to create handler classes.Note that start() mast still not called.
 
Handy class for starting a new thread that has a looper.
//这是一个可以很便捷地获取一个Looper来开启一个新线程的类。(这是一个方便创建新线程并拥有looper的类)
The looper can than be used to create handler classes.
//可以利用这个looper创建一盒Handler类。(也就是带looper的handler)
Note that start() mast still not called.
//注意此时start()方法还没调用。
 
Public Constructor//公共构造器
public HandlerThread(String name)
public HandlerThread(String name,int priority)
parameters //参数
priority The priority to run the thread at.The values supplied must be from Procces and not from java.lang.Thread.
//优先级 这个优先级是运行在线程里的,它的值必须是是进程中支持的而非线程。
 
Public Method
public Looper getLooper()
The method returns the looper associated whit this thread.If this thread not been started or for any reason is Alive() returns false,this method will return null.If this thread has been started,this method will brock until the looper has been initialized.
 
The method returns the looper associated whit this thread.
//这个方法将会返回一个和线程关联的looper。
If this thread not been started or for any reason is isAlive() returns false,this method will return null.
//如果这个线程没被执行或者由于任何原因 isAlive()返回假的时候,这个方法将会返回空。
If this thread has been started,this method will brock until the looper has been initialized.
//如果这个线程已经开始运行了,这个方法将会阻塞除非looper已经被初始化。
 
public int getThreadId()
Retunrs the ind identifier of this thread.See Procces.myPid.
//返回这个线程的标识符,见Procces.myPid。
 
public boolean quit()
Ask the currenty running looper to quit.If this thread has not been started or has finished(that is if getLooper() returns null),then false is returned.Otherwise  the looper is asked quit and true is return.
//呼叫当前正在运行中的looper消息循环退出。如果这个线程没有开始或者线程已经执行完毕(getLooper 将返回空),就返回假。否则将退出消息循环并返回真。
 
public void run()
Calls the run() method of the Runnable object the receiver holds.If no Runnable set,does nothing.
//Runnable 对象调用这个方法...不懂,如果没有对象设置,就不做任何事。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值