Avatar:安卓跨进程事件订阅发布
阿凡达:一个解决跨进程的事件订阅发布问题:
项目地址Avatar
1:跨进程通信 aidl+service
2:发布的内容和订阅者的信息进程共享
跨进程的通信可用采用binder机制,这里用 aild.stub 的 binder 代理对象
订阅发布可用采用CS架构,将订阅信息和发布内容同步到一个Service,保证进程间数据一致
选择service+adil的原因:
①service 四大组件之一,由AMS管理,提供binder接口,可用传入 Messager.Binder/Aidl.Stub 等 IBinder的实现,来实现跨进程通信
②启动service:采用bind 启动,保证了客户端bindService(intent,binder,connection)后,Service的onBind()方法通过AMS代理将binder传递到AMS,ServiceDispatcher.ConnectionInfo,将binder的connect/disconnect的回调(ServiceConnection)返回给客户端
③每个进程有一份Avatar,每次register/unregister/post 都会通过bindService,向服务器Service发送订阅者和订阅内容,在Service进行同步和转发
使用:
Step 1. Add the JitPack repository to your build file
Add it in your root build.gradle at the end of repositories:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Step 2. Add the dependency
dependencies {
implementation 'com.github.woaigmz:Avatar:0.0.1'
}
**Step 3.每个进程初始化 context 上下文,通过上下文来启动service
public class App extends Application {
@Override
public void onCreate() {
super