Git Product home page Git Product logo

and-ipc's Introduction

and-ipc

and-ipc 一个使用AIDL实现的Android 应用内多进程间通信解决方案。

👏 特性

  • 支持 跨进程发送信息;
  • 支持 跨进程发送信息并接收消息回调;

👨‍💻‍ 依赖方式

Gradle(Project Setting)

//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' }
		}
	}

Gradle (Module app)

//Add the dependency
dependencies {
	        implementation 'com.github.quexs-and:and-ipc:1.0.0'
	}

👨‍🔧‍ 使用方式

绑定IPC服务

使用进程名作为IPC服务消息接收的标签(默认)

//在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单独绑定消息接收的标签

//在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) {
                //接收单次回调的消息
            }
        });

and-ipc's People

Contributors

quexs-and avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.