我已经用过
EventBus
在项目中。我有一个导航抽屉,我可以从中导航碎片。我所面临的是我正在尝试注册EventBus
onCreateView()
使用的碎片
GlobalBus.getBus().register(this)
然后我打开抽屉,打开第二块碎片。当我打开抽屉重新打开第一块碎片时,
onCreateView()
被叫和
globalBus.getBus().register(这个)
又打电话来了。再次注册EventBus(两次、三次和多次)
所以为了不再注册,我做了
if (!GlobalBus.getBus().isRegistered(this))
GlobalBus.getBus().register(this)
但它总会回来
假
.
我已从注销EventBus
override fun onDestroyView() {
GlobalBus.getBus().unregister(this)
}
有人能告诉我为什么吗
如果(!)globalBus.getBus().isRegistered(this))
globalBus.getBus().register(这个)
不工作?我怎样才能为任何片段只注册一次,这样订户方法就不会调用多次呢?