Defining events

First, we will define the POJO classes that would be submitted in the Bus by the publisher to notify the interested entities whether the mobile network connectivity is available or not:

public class MobileNetConnectedEvent{
  public final String detailedState;
  public MobileAvailableEvent(String detailedState) {
    this.detailedState = detailedState;
  }
}
public class MobileNetDisconnectedEvent {}

The MobileNetConnectedEvent event is a POJO class that will be sent when the mobile network is available and will carry a string message with the detailed network state.

The MobileNetDisconnectedEvent is an event that does not carry any information but it will notify the event subscriber that connection with the network was lost.

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.