and-ipc 一个使用AIDL实现的Android 应用内多进程间通信解决方案。
- 支持 跨进程发送信息;
- 支持 跨进程发送信息并接收消息回调;
//Add it in your root build.gradle at the end of repositories
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
//Add the dependency
dependencies {
implementation 'com.github.quexs-and:and-ipc:1.0.0'
}
//在activity或者service的onCreate()中创建
andIPC = new AndIPC(this, new AndIPCCallback.Stub() {
@Override
public void receiveMessages(String sourceKey, String message, boolean isNeedCallback) throws RemoteException {
//接收消息
//TODO 此处处理消息
if(isNeedCallback){
//需要回调
andIPC.sendMessage(sourceKey, "message(回调的消息体)");
}
}
});
//绑定服务
andIPC.bindIPCService();
//注:应在onDestroy()解绑service
andIPC.unbindIPCService();
//在activity或者service的onCreate()中创建
andIPC = new AndIPC(this, "ownTag(自定义消息接收的标签)", new AndIPCCallback.Stub() {
@Override
public void receiveMessages(String sourceKey, String message, boolean isNeedCallback) throws RemoteException {
//接收消息
//TODO 此处处理消息
if(isNeedCallback){
//需要回调
andIPC.sendMessage(sourceKey, "message(回调的消息体)");
}
}
});
//绑定服务
andIPC.bindIPCService();
//注:应在onDestroy()解绑service
andIPC.unbindIPCService();
andIPC.sendMessage("targetTag(目标进程消息接收标签)", "message(消息体)");
andIPC.sendMessage("targetTag(目标进程消息接收标签)", "onceTag(临时消息接收标签)", "message(消息体)", new OnceIpcCallbackListener() {
@Override
public void receiveMessages(String sourceTag, String message, boolean isNeedCallback) {
//接收单次回调的消息
}
});