2

I am creating a library on Android using EventBus.

I am posting an event in my library.

EventBus.getDefault().post(new ConnectToDataEvent(Constants.AUTH,true));

The app module is registered to listen for events.

 @Override
public void onStart() {
    super.onStart();
    EventBus.getDefault().register(this);
}

@Override
public void onStop() {
    super.onStop();
    EventBus.getDefault().unregister(this);
}

The Subscribe method:

@Subscribe(threadMode = ThreadMode.MAIN)
public void onMessageEvent(ConnectToDataEvent event) {

    loginonClick();
  };

I am receiving

No subscribers registered for event

Is this the right way to use in a library or it is not possible at all?

Any help is appreciated.

ישו אוהב אותך
  • 28,609
  • 11
  • 78
  • 96
user2536851
  • 314
  • 3
  • 11

1 Answers1

1

No subscribers registered for event

This is usually because your Activity is not visible anymore, so the onStop() is already called and the EventBus has already been unsubcribed.

You need to remove the onStop() part and try moving the unregister part to onDestroy():

@Override
public void onDestroy() {
    EventBus.getDefault().unregister(this);

    super.onDestroy();
}
ישו אוהב אותך
  • 28,609
  • 11
  • 78
  • 96