Registering sbscribers

With the Publisher/Sender class and event class already specified, all that remains is to register our Activity class to receive both events and print the event sent on the screen.

Like we stated before, to receive any event from the Bus, the Subscriber entity, which could be any Java class on your code, will have to register on the Bus and subscribe to the event that it is interested in.

Any object will have to register on the Bus by calling the register function and provide a single on<EventName>(EventType) method annotated with org.greenrobot.eventbus.Subscribe for all the kind of event that it is interested in:

@Subscribe
void on<EventClassname>(EventClassname event) {
 ...
}

Let's implement the functions that are going to ...

Get Asynchronous Android Programming - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.