Don't unregister the listener if it was never registered.

This commit is contained in:
Braden Shepherdson 2012-09-24 14:37:04 -04:00
parent 2cd3ebc7a8
commit faa034a205

View File

@ -69,6 +69,7 @@ public class NetworkManager extends Plugin {
private static final String LOG_TAG = "NetworkManager"; private static final String LOG_TAG = "NetworkManager";
private String connectionCallbackId; private String connectionCallbackId;
private boolean registered = false;
ConnectivityManager sockMan; ConnectivityManager sockMan;
BroadcastReceiver receiver; BroadcastReceiver receiver;
@ -103,6 +104,7 @@ public class NetworkManager extends Plugin {
} }
}; };
cordova.getActivity().registerReceiver(this.receiver, intentFilter); cordova.getActivity().registerReceiver(this.receiver, intentFilter);
this.registered = true;
} }
} }
@ -144,9 +146,10 @@ public class NetworkManager extends Plugin {
* Stop network receiver. * Stop network receiver.
*/ */
public void onDestroy() { public void onDestroy() {
if (this.receiver != null) { if (this.receiver != null && this.registered) {
try { try {
this.cordova.getActivity().unregisterReceiver(this.receiver); this.cordova.getActivity().unregisterReceiver(this.receiver);
this.registered = false;
} catch (Exception e) { } catch (Exception e) {
Log.e(LOG_TAG, "Error unregistering network receiver: " + e.getMessage(), e); Log.e(LOG_TAG, "Error unregistering network receiver: " + e.getMessage(), e);
} }