简体   繁体   English

奥托(Otto):片段订阅未收到事件

[英]Otto: Fragment subscriptions not receiving events

I've got a fragment and have registered and unregistered the bus in the fragments onResume and onPause methods. 我有一个片段,并在片段的onResumeonPause方法中注册和注销了总线。 Using the following BusProvider.getInstance().register(this); 使用以下BusProvider.getInstance().register(this); and BusProvider.getInstance().unregister(this); BusProvider.getInstance().unregister(this); .

I have a subscription defined like so: 我有一个这样定义的订阅:

@Subscribe public void onLogin(LoggedInEvent event) {
    // Do Something
}

I also have another subscription for the same event in the activity the fragment is attached to and that subscription reacts and does it's thing. 在片段附加到的活动中,我还对同一事件进行了另一项订阅,该订阅做出了反应并且确实如此。 So my question is why doesn't my fragment receive the event for LoggedInEvent ? 所以我的问题是为什么我的片段不接收LoggedInEvent的事件?

Edit: I've also registered/unregistered the bus in my activity's onResume and onPause methods as well. 编辑:我也已经在活动的onResumeonPause方法中注册/注销了总线。

Edit 2: The bus was instantiated with ThreadEnforcer.ANY 编辑2:总线已使用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. 我发现正在将事件发布到总线上的类,但是没有在主/ ui线程上运行,这导致不一致,因为它们能够看到ui中发生的更改并做出正确的反应。 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. 因此,现在我的班级正在发布在主线程上,并且从创建总线中删除了ThreadEnforcer.ANY ,从而确保所有内容都可以在主线程上运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM