Use Case Android: listen to connection state changes within a LiveData object

It’s a common use case in an android app to warn your app user he’s not connected anymore or refresh data when the network is back.
With LiveData, it’s become very easy to do so. Thanks to the broadcast receiver for connectivity change, we are pinged during a change and can determine exactly all the info needed from the network with the ConnectivityManager.
According to the google doc, it’s more resource friendly to register a broadcast receiver when needed. That’s why with a live data object, if no one is observing it, the broadcast receiver is not registered. On the contrary, as soon as the live data object is not active anymore, we unregister the broadcast receiver. We can apply this network status listener only in views where it matters for the app users.