Reader small image

You're reading from  Asynchronous Android Programming - Second Edition

Product typeBook
Published inJul 2016
Reading LevelBeginner
PublisherPackt
ISBN-139781785883248
Edition2nd Edition
Languages
Tools
Right arrow
Author (1)
Steve Liles
Steve Liles
author image
Steve Liles

Steve Liles is a self-confessed geek and has been an Android fan since the launch day of the G1. When he isn't at work building publishing systems and apps for newspapers and magazines, you'll find him tinkering with his own apps, building 3D printers, or playing RTS games. He is currently working with a start-up to build an advertising system that links the print and digital worlds using computer vision on Android and iOS devices.
Read more about Steve Liles

Right arrow

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 handle the MobileNetDisconnectedEvent and the MobileNetConnectedEvent event in our Activity:

@Subscribe
public void 
onMobileNetDisconnectedEvent(MobileNetDisconnectedEvent event){

  String message = String.format(
    "Mobile connection...
lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Asynchronous Android Programming - Second Edition
Published in: Jul 2016Publisher: PacktISBN-13: 9781785883248

Author (1)

author image
Steve Liles

Steve Liles is a self-confessed geek and has been an Android fan since the launch day of the G1. When he isn't at work building publishing systems and apps for newspapers and magazines, you'll find him tinkering with his own apps, building 3D printers, or playing RTS games. He is currently working with a start-up to build an advertising system that links the print and digital worlds using computer vision on Android and iOS devices.
Read more about Steve Liles