In my android application I am unregistering a networkCallback onPause of an activity. There are times where I can get the error, Caused by
java.lang.IllegalArgumentException
NetworkCallback was already unregistered
Is there a way to check if the network callback already was unregistered or to prevent "double" unregistering? Or registered so we known when to call unregister?
if (mNetworkCallback != null && mConnectivityManager != null) {
try{
mConnectivityManager.unregisterNetworkCallback(mNetworkCallback);
}
catch (Exception e){
Log.d(TAG, "unregister failed");
}
}
There is no method to check if the network is already unregistered.
try{
//your code
}
catch (IllegalArgumentException exception){
//network is already unregistered
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With