android中线程之间的信息传递

Handler


java.lang.Object
   ↳android.os.Handler
Known Direct Subclasses

原意:

A Handler allows you to send and process Message and Runnable objects associated with a thread's MessageQueue. Each Handler instance is associated with a single thread and that thread's message queue. When you create a new Handler, it is bound to the thread / message queue of the thread that is creating it -- from that point on, it will deliver messages and runnables to that message queue and execute them as they come out of the message queue.

译文:

一个Handler允许你去发送并且处理信息而且Runnable接口对象是和我们的一个线程MessageQueue相联系的。每个Handler实例与单个线程,该线程的消息队列相关联的。当您创建一个新的Handler它是绑定到线程/消息的线程产生了这个队列 -从这点上来看,它会提供信息,并到该消息队列的Runnable并执行他们,因为他们消息出来队列。


Handler的主要作用:

Handler主要是用来跟UI主线程交互用。 比如:
1、你用handler发送一个message,然后在handler的线程中来接收、处理该消息,以避免直接在UI主线程中处理事务导致影响UI主线程的其他处理工作。
2、你可以将handler对象传给其他进程,以便在其他进程中通过handler给你发送事件。
3、通过handler的延时发送message,可以延时处理一些事务的处理 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值