Otto: Fragment subscriptions not receiving events

2019-09-09 16:30发布

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

标签: android otto
1条回答
劫难
2楼-- · 2019-09-09 17:04

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.

查看更多
登录 后发表回答