I am using ReactiveNetwork to observe my wifi. I added a callback that when the wifi gets disconnected, an alert dialog pops up. However, the dialog gets pop up when wifi is turned off while the app is not shown (home). I want to unsubscribe but I can't find the correct way to do the corresponding unsubscribe for this method. How do I unsubscribe?
ReactiveNetwork.observeNetworkConnectivity(context)
.subscribeOn(Schedulers.io())
.filter(ConnectivityPredicate.hasType(ConnectivityManager.TYPE_WIFI))
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Consumer<Connectivity>() {
@Override
public void accept(final Connectivity connectivity) {
if(connectivity.isAvailable()) {
callback.onWifiConnected();
}
else {
callback.onWifiDisconnected();
}
}
});