GithubHelp home page GithubHelp logo

processmessenger's Introduction

ProcessMessenger

Android 进程通信,实现了 Android 跨进程、跨 App 通信的方便调用和封装。

第一步,初始化:

ProcessMessenger.init(this);

第二步,订阅消息和取消订阅:

订阅消息:

ProcessMessenger.subscribe(String key, MessageCallback callback);

实例:

ProcessMessenger.subscribe("service", new MessageCallback() {
    @Override
    public void onReceive(Bundle data) {
        String message = data.getString("name");
        Log.e("service", "收到消息 -> " + message);
        Toast.makeText(TestService.this, message, Toast.LENGTH_SHORT).show();
    }
});

取消订阅:

ProcessMessenger.unsubscribe(String key, MessageCallback callback);

第三步,发送消息:

ProcessMessenger.sendMessage(String key, Bundle data);

订阅消息和发送消息第一个参数是消息的标志,需要唯一;消息依赖 bundle 传递,发送消息第二个参数可传递类型跟 Bundle 允许类型一致。

processmessenger's People

Contributors

zhaomenghuan avatar

Stargazers

MinuitZ avatar

Watchers

James Cloos avatar  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.