First you need to define a custom message event class:
public class MyMessageEvent { String s; }
Then you must add the subscriber method to your service. The key point is to include your MyMessageEvent
as a parameter:
public void onEventBackgroundThread(MyMeasageEvent myEvent){ Log.d(TAG, "onEventBackgroundThread: " + myEvent.s); }
Also, make sure your service is registered using EventBus
.
Finally, create a MyMessageEvent
in your activity and host it in the eventbus:
MyMessageEvent myEvent = new MyMessageEvent() ; myEvent.s = "hello" ; EventBus.getDefault().post(myEvent) ;
If it is still not received, try splitting the message into a separate line by default. Sometimes the chain doesn't work.
Dezra source share