Otto: Fragment subscriptions not receiving events

心不动则不痛 提交于 2019-12-25 07:29:24

问题


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
}

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?

Edit: I've also registered/unregistered the bus in my activity's onResume and onPause methods as well.

Edit 2: The bus was instantiated with ThreadEnforcer.ANY


回答1:


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.



来源:https://stackoverflow.com/questions/24253962/otto-fragment-subscriptions-not-receiving-events

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!