奥托:片段订阅不接收事件 [英] Otto: Fragment subscriptions not receiving events
问题描述
我有一个片段,并已注册,并在片段 onResume
和的onPause
方法注销总线。使用以下 BusProvider.getInstance()寄存器(本);
和 BusProvider.getInstance()注销(本);
。
I've got a fragment and have registered and unregistered the bus in the fragments onResume
and onPause
methods. Using the following BusProvider.getInstance().register(this);
and BusProvider.getInstance().unregister(this);
.
我有一个像这样定义的订阅:
I have a subscription defined like so:
@Subscribe public void onLogin(LoggedInEvent event) {
// Do Something
}
我也有另一个订阅在片段附着到活动相同的事件,并且订阅反应并执行它的东西。所以我的问题是,为什么没有我的片段收到 LoggedInEvent
?
编辑:
我也注册/未注册在公交车上我活动的 onResume
和的onPause
方法为好。
编辑2:
公交车与 ThreadEnforcer.ANY
推荐答案
我想通了,这是张贴的事件到总线上,但不是主/ UI线程这是造成inconstancies用能运行的类看到变化发生在UI和正确的反应。所以,现在我的类被张贴在主线程上,我从创建我的车删除 ThreadEnforcer.ANY
让现在一切可以肯定的是主线程上运行。
I figured out that the class that was posting the events to the bus, but wasn't running on the main/ui thread which was causing inconstancies with being able to see changes happen in the ui and reacting properly. So now my class is posting on the main thread and I removed the ThreadEnforcer.ANY
from creating my bus so that now everything for sure is running on the main thread.
这篇关于奥托:片段订阅不接收事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!