美文网首页
Android简单易用的通信框架

Android简单易用的通信框架

作者: AndroidLazy | 来源:发表于2019-10-08 14:01 被阅读0次

    优点:简便轻量型、速度快、易维护、可拿返回值

    缺点:单处接收

    1. 页面之间的通信,(Activity之间 或者 fragment之间 或者 Activity与fragment之间)

    2. 使用可以带参数和拿到返回值,(EventBus没有返回值)

    3. 设置事件 FunctionManager.getInstans().addFunction(function);

    传入的function可以是以下几种:

    FunctionNoParamNoResult:不带参数和返回值

    FunctionWithParamOnly:只带参数

    FunctionWithParamBouble:带两个参数

    FunctionWithResultOnly:只需要返回值

    FunctionWithParamWithResult:带参数和返回值

    FunctionWithDoubleParamWithResult:带两个参数和返回值

    例如:

    FunctionManager.getInstans().addFunction(new FunctionWithDoubleParamWithResult(CommunicationConstants.TEST) {

    @Override

    public Integer function(Integer param, Integer integer) {

    return param + integer;

    }

    });

    4. CommunicationConstants.TEST是事件名字,尽量在项目定义一个常量类来规范使用,并且需要保证唯一性,方便维护

    5. 调用事件

    例如:

    Integer integer = FunctionManager.getInstans().invokeFunc(CommunicationConstants.TEST, 1, 3, Integer.class);

    6. 在设置事件的页面的销毁时移除事件减少内存

    例如:

    FunctionManager.getInstans().removeFunction(CommunicationConstants.TEST);

    最后欢迎下载demo了解使用,demo地址:https://gitee.com/musiccrazy/communication.git

    相关文章

      网友评论

          本文标题:Android简单易用的通信框架

          本文链接:https://www.haomeiwen.com/subject/xisbpctx.html