Android Messager的使用

在Android系统的IPC通讯中,其中以Binder尤为重要,即可在native层玩转,也可在java层有余.

对于要讨论的Messager通讯,应该属于在研究系统时的意外发现,毕竟它不是很常用,也很少看到。

这个功能要从SystemUI的解图功能开始:

 

 

请留意图中的Binder,即整个Messager通讯机制也是建立在Binder之上。

来看看A进程的IMessage是怎么传过来的:

对的,就是在Onbind的时候传过来的。

看看API文档:

Messenger

public final class Messenger 
extends Object implements Parcelable

java.lang.Object
   ↳android.os.Messenger

 


Reference to a Handler, which others can use to send messages to it. This allows for the implementation of message-based communication across processes, by creating a Messenger pointing to a Handler in one process, and handing that Messenger to another process.

Note: the implementation underneath is just a simple wrapper around a Binder that is used to perform the communication. This means semantically you should treat it as such: this class does not impact process lifecycle management (you must be using some higher-level component to tell the system that your process needs to continue running), the connection will break if your process goes away for any reason, etc.

也就只有这么些。

 

当然如果要问他的局限性,那么就是Message的局限性,限制了大数据的传递,而且当没有很好的错误处理机制:

文档里面说的也很明了,没有生命周期管理,你需要在把你的进程更高的优先级使用它,如果你的进程死掉,那么他们之间的通讯也会端掉的。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值