The online class can be used to inquire about the current online status, as well as register a listener when it changes. Note: The listener can only be triggered when the device is online again. So it’s only worth testing for when the device comes back online, rather than offline.


// Get current online state (This should always be online)

// Registration of Listeners, in order to test when the user comes back online
final Online online = new Online(this);
final Registration registration = online.addOnlineListener(onlineState -> {
  // ...Do something once the user is online again...

// and once we no longer need the registration, we can remove it