HandlerThread
来源:互联网 发布:网络诈骗罪判决书 编辑:程序博客网 时间:2024/06/05 21:09
我们在一个线程中使用Handler的步骤
- Looper.prepare()创建与当前线程绑定的Looper
- Handler handler = new Handler(Looper.myLooper())
- Looper.loop()开启循环访问消息队列
对于Handler机制的原理,可以参考http://blog.csdn.net/actor1999/article/details/70210901
HandlerThread继承Thread,它的run()方法为
@Overridepublic void run() { mTid = Process.myTid(); Looper.prepare(); synchronized (this) { mLooper = Looper.myLooper(); notifyAll(); } Process.setThreadPriority(mPriority); onLooperPrepared(); Looper.loop(); mTid = -1;}
HandlerThread使用:
HandlerThread handlerThread = new HandlerThread();handlerThread.start();Handler handler = new Handler(handler.getLooper());
可以看出HandlerThread就是将我们使用Handler要做的事情封装一下而已。
0 0
- HandlerThread
- HandlerThread
- HandlerThread
- HandlerThread
- HandlerThread
- HandlerThread
- HandlerThread
- HandlerThread
- HandlerThread
- HandlerThread
- HandlerThread
- HandlerThread
- HandlerThread
- HandlerThread
- handlerThread
- HandlerThread
- HandlerThread
- HandlerThread
- 思科模拟器常用命令总结(续)
- 最新版Intellij IDEA插件JRebel 7.0.7官方免费激活
- 为nginx创建windows服务自启动
- 程序猿必修课之数据结构(二)算法和算法的复杂度
- 【新产品】.NET条形码控件 Spire.Barcode for .NET发布
- HandlerThread
- JS基础知识
- Diagonal Traverse
- $_GET
- js中常用字符串和数组的操作方法
- 欢迎使用CSDN-markdown编辑器
- 关于写toolbar加入Menu时候遇到的问题
- [Lpp]Linux系统简介
- 关于字符编解码