I am trying to use guava for subscribing to EventBus. Trying to look at the site doc but unable to see any example where it shows how to do it.
Anyone tried this before??
private final EventBus eventBus = new EventBus();
eventBus.post(eventId); // where eventId is a string.
This is being in one of the jars. Now I need to subscribe to this eventbus and check if there are any new eventId's posted. How can I do that?
Any help is appreciated.
Thanks!!
You would need some object with a method annotated @Subscribe
that takes a parameter of type String
(since you're posting a String
as an event to it... note that some more specific event type is probably preferable). You then need to pass that object to the EventBus.register(Object) method. Example:
public class Foo {
@Subscribe
public void handleEvent(String eventId) {
// do something
}
}
Foo foo = ...
eventBus.register(foo);
eventBus.post(eventId);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With