public DemoEvent(String content) {
this.content = content;
}
}
//发送消息
LiveEventBus
.get(DemoEvent.class)
.post(new DemoEvent(“Hello world”));
4、在Application.onCreate方法中配置:
《Android学习笔记总结+最新移动架构视频+大厂安卓面试真题+项目实战源码讲义》
【docs.qq.com/doc/DSkNLaERkbnFoS0ZF】 完整内容开源分享
LiveEventBus
.config()
.autoClear(true)
.lifecycleObserverAlwaysActive(true);
- lifecycleObserverAlwaysActive
配置LifecycleObserver(如Activity)接收消息的模式(默认值true):
true:整个生命周期(从onCreate到onDestroy)都可以实时收到消息
false:激活状态(Started)可以实时收到消息,非激活状态(Stoped)无法实时收到消息,需等到Activity重新变成激活状态,方可收到消息
- autoClear
配置在没有Observer关联的时候是否自动清除