Android HandlerThread

来源:互联网 发布:细说php第二版 pdf 编辑:程序博客网 时间:2024/06/05 21:49


/**
 * Handy class for starting a new thread that has a looper. The looper can then be 
 * used to create handler classes. Note that start() must still be called.
 */
public class HandlerThread extends Thread 

从类的说明中可以看出,它是一个新的线程,不是UI线程,并且有自己的looper,也就是说,有自己的消息处理。一般情况下,主线程默认有消息处理,也就是mainLooper,其它线程是没有消息处理的,那么这个HandlerThread,是一个worker线程,并且有消息处理机制。
如何区分是主线程还是work线程呢?
Thread.currentThead().getName(),就能看到线程名称:比如主线程的名称是:main,主线程默认有一个消息处理器,就是MainLooper,比如上面的HandlerThread,就要自己建立Looper,实现自己线程内的消息处理。


参考链接:
http://topmanopensource.iteye.com/blog/1246864
http://www.linuxidc.com/Linux/2012-07/64602.htm
  

0 0
原创粉丝点击