一、Handler、Looper、Message、MessageQueue类功能简介1.1 Message 消息类,定义了发送给Handler对象的包含描述和二进制数据对象的消息对象。这个类比较重要的字段: what:消息码用于接收者识别是啥消息,每个Handler对象有自己的命名空间用于消息...
分类:
移动开发 时间:
2015-08-31 13:29:19
阅读次数:
143
Android中除了UI线程(主线程),创建的工作线程默认是没有消息循环和消息队列的。如果想让该线程具有消息队列和消息循环,并具有消息处理机制,就需要在线程中首先调用Looper.prepare()来创建消息队列,然后调用Looper.loop()进入消息循环。classLooperThreadextendsThread{pu..
分类:
移动开发 时间:
2015-08-30 01:14:35
阅读次数:
953
android异步消息处理主要由四部分组成:Handler,Looper,Message,MessageQueue Message:线程之间传递的消息,可以在内部携带少量消息 MessageQueue: Looper:每个线程有且最多只能有一个Looper对象,它是一个...
分类:
移动开发 时间:
2015-08-29 14:07:47
阅读次数:
163
一.启动Activity需要两个Binder线程(Binder_1;Binder_2)的支持。启动Service同样需要。 他俩的主线程都是ActivityThread。 Looper.loop()是在ActivityThread的main(string[] args)中被调用的public s.....
分类:
移动开发 时间:
2015-08-19 19:11:28
阅读次数:
151
public static boolean isInMainThread() { return Looper.myLooper() == Looper.getMainLooper();}
分类:
移动开发 时间:
2015-08-19 16:14:21
阅读次数:
120
先膜拜下大神的帖子,从源码的角度分析android的Handler机制。 链接:android的消息处理机制(图+源码分析)——Looper,Handler,Message 这里就不赘言,仅仅做一些介绍,想看详细请猛戳上面的链接。 android的消息机制由三块组成Looper,Handl...
分类:
移动开发 时间:
2015-08-18 21:16:53
阅读次数:
138
http://cthhqu.blog.51cto.com/7598297/1283673 http://www.cloudchou.com/android/post-388.html http://superonion.iteye.com/blog/1442416 http://vjson.com/wordpress/handler-looper原理分析.html ? http:/...
分类:
其他好文 时间:
2015-08-17 21:58:12
阅读次数:
120
闲着没事,就来看看源码,看看源码的各种原理,会用只是简单的,知道为什么才是最牛逼的。
Handler源码分析那,从使用的步骤来边用边分析:
1.创建一个Handler对象:new Handler(getMainLooper(),this);
这是我常用的一个方式,getMainLooper是获取主线程的Looper,this则是实现CallBack的接口
看一下...
分类:
移动开发 时间:
2015-08-17 21:56:34
阅读次数:
185
1.一个线程可以有多个Handler2.一个线程只有一个Looper,和一个消息队列MessageQueue3.如果没有指定,Handler在哪个线程创建,就用哪个线程的Looper4.除了主线程,其他的线程都需要先调用Looper.prepare()方法,创建Looper,再用looper.loo...
分类:
其他好文 时间:
2015-08-17 09:57:09
阅读次数:
126
Handler相关博文:
Android中Handler的使用
深入源码解析Android中的Handler,Message,MessageQueue,Looper
Android新线程中更新主线程UI中的View方法汇总
Android中HandlerThread的使用及原理解析
Android中Looper的quit方法和quitSafely方法Service相关博文:...
分类:
移动开发 时间:
2015-08-16 00:40:58
阅读次数:
170