• Stars
    star
    156
  • Rank 232,167 (Top 5 %)
  • Language
    Java
  • License
    Apache License 2.0
  • Created over 5 years ago
  • Updated about 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

📮SmartEventBus是一个Android平台的消息总线框架,这是一款非常smart的消息总线框架,能让你定制自己的消息总线。

SmartEventBus

license version

SmartEventBus是一个Android平台的消息总线框架,这是一款非常smart的消息总线框架,能让你定制自己的消息总线。

logo

常用消息总线对比

消息总线 延迟发送 有序接收消息 Sticky 生命周期感知 跨进程/APP Customize(定制能力) 线程分发
EventBus
RxBus
LiveEventBus
SmartEventBus

想了解更多?请点击:全面了解Android消息总线

SmartEventBus的使用步骤

1. 定义消息

@SmartEvent(keys = {"event1", "event2", "event3"})
public class MessageEvent {

    public String msg;

    public MessageEvent(String msg) {
        this.msg = msg;
    }
}

2. 配置你的消息总线(可选)

@SmartEventConfig(packageName = "yourPackageName", busName = "YourClassName")
public class BaseEventConfig {
}
  • 配置之后,会生成定制消息总线:yourPackageName.YourClassName
  • 也可以不配置,生成默认命名DefaultSmartEventBus的消息总线

3. 订阅和发送消息

MySmartEventBus
        .event1()
        .observe(this, new Observer<MessageEvent>() {
            @Override
            public void onChanged(@Nullable MessageEvent event) {
            }
        });
MySmartEventBus
        .event1()
        .post(new MessageEvent("msg from smarteventbus"));

4. 添加依赖和注解处理器

implementation 'com.jeremyliao:smart-event-bus-base:0.0.1'
annotationProcessor 'com.jeremyliao:smart-event-bus-compiler:0.0.2'

混淆规则

-dontwarn com.jeremyliao.liveeventbus.**
-keep class com.jeremyliao.liveeventbus.** { *; }

SmartEventBus的前身——invoking-message

其他