换到 Kotlin 后,之前的 EventBus 不能正常用,发现这个还挺好用的。
依赖:
compile 'com.eightbitlab:rxbus:1.0.2'
注意事项:
- 可以直接在 Fragment 中使用,不用 Activity 中使用后再发送事件到 Fragment。
注册和接收事件:
Bus.observe<UpdatePersonInfoEvent>()
.subscribe {
personInfo(it)
}
.registerInBus(this)
取消注册:
Bus.unregister(this)
发送事件:
Bus.send(UpdatePersonInfoEvent(true))
网友评论