HermesEventBus跨进程通信(饿了么开源)

  EventBus 是一款在 Android 平台发布的 发布/订阅 事件总线,主要用来替代 Intent,Handler,Broadcast 在 Fragment,Activity,Service,线程之间传递消息,简化各组件之间的通讯,优点开销小,代码优雅,能够很好的解耦业务与界面交互,缺点是很容易混淆程序逻辑,而且无法进程间通信。
  HermesEventBus 拥有 EventBus 全部的作用和相同的 API (内部依赖EventBus),支持跨进程。HermesEventBus本质上也是通过AIDL实现跨进程通信,依赖于主进程的Service载体。使用HermesEventBus省去了自己实现跨进程通信的烦恼。
-- HermesEventBus-饿了么开源的Android跨进程事件分发框架
 A library for using EventBus between processes, useful in the IPC or plugin development- https://github.com/Xiaofei-it/HermesEventBus
 HermesEventBus是一种支持跨进程,跨APP通信的以EventBus为基础的框架- https://github.com/elemers/HermesEventBus
 HermesEventBusDemo进程间通信的新姿势- https://github.com/TaroXin/HermesEventBusDemo
 HermesEventBus-饿了么开源的Android跨进程事件分发框架- http://lrd.ele.me/2016/07/13/HermesEventBus-%E4%B8%80%E7%A7%8D%E6%96%B0%E7%9A%84Android%E8%B7%A8%E8%BF%9B%E7%A8%8B%E4%BA%8B%E4%BB%B6%E5%88%86%E5%8F%91%E6%A1%86%E6%9E%B6/?hmsr=toutiao.io&utm_medium=toutiao.io&utm_source=toutiao.io

-- 几种跨进程方法:
  1.BroadCastReceiver 由于面向整个系统注册的广播,跨进程消耗较大,性能不能保证。
  2.ContentProvider 支持跨进程数据共享
AIDL 客户端调用;
  3.AIDL接口是同步并且带返回结果的,如果执行时间较长,客户端的调用线程会一直等待。服务端执行AIDL接口是异步的,支持所有基本类型、AIDL接口、Parcelable、List、Map等类型的参数,实现起来繁琐。
  4.Messenger 本质是AIDL通信,客户端发送Message后不带返回结果,服务端接收到Message是通过一个线程的Handler轮询MessageQueue处理的,因此处理Message是在同一线程。
  5.HermesEventBus 本质也是AIDL通信,不需要自己实现绑定Service,发送事件也是不带返回结果的,使用简单。
  6.Binder机制 Android跨进程通信实现的核心,AIDL就是基于Binder机制实现的,其中transact方法是客户端向服务端发送消息,onTransact方法是客户端接收服务端的消息。

猜你喜欢

转载自blog.csdn.net/shareus/article/details/81008320