As I understand, the method hasSubscriberForEvent(Class<?> eventClass)
from EventBus should return true if I'm listening for any Event on this eventClass
. But it always returns false, I'm not sure why.
In my fragment I register and unregister the EventBus, and declare the method to listen the Post:
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
EventBus.getDefault().register(this);
super.onCreate(savedInstanceState);
}
@Override
public void onDestroy() {
EventBus.getDefault().unregister(this);
super.onDestroy();
}
public void onEvent(MyDummyObject event) {
Log.i(TAG,"event received!");
}
In my service I need to check if this Fragment is visible or not, one way to do it I assumed would be using EventBus.getDefault().hasSubscriberForEvent(MyFragment.class)
.
I expected that if EventBus would see that MyFragment
has anything registered would return true, otherwise would return false.
Am I missing something, or hasSubscriberForEvent()
does not behave this way?
Note: If I do EventBus.getDefault().post(new MyDummyObject());
the event fires, so I assume the EventBus is being registered and unregistered successfully.