From faa034a2053ac6988bf5196fc3ad88feb143657f Mon Sep 17 00:00:00 2001 From: Braden Shepherdson Date: Mon, 24 Sep 2012 14:37:04 -0400 Subject: [PATCH] Don't unregister the listener if it was never registered. --- framework/src/org/apache/cordova/NetworkManager.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/framework/src/org/apache/cordova/NetworkManager.java b/framework/src/org/apache/cordova/NetworkManager.java index e3ec9a9f..4a9d6582 100755 --- a/framework/src/org/apache/cordova/NetworkManager.java +++ b/framework/src/org/apache/cordova/NetworkManager.java @@ -69,6 +69,7 @@ public class NetworkManager extends Plugin { private static final String LOG_TAG = "NetworkManager"; private String connectionCallbackId; + private boolean registered = false; ConnectivityManager sockMan; BroadcastReceiver receiver; @@ -103,6 +104,7 @@ public class NetworkManager extends Plugin { } }; cordova.getActivity().registerReceiver(this.receiver, intentFilter); + this.registered = true; } } @@ -144,9 +146,10 @@ public class NetworkManager extends Plugin { * Stop network receiver. */ public void onDestroy() { - if (this.receiver != null) { + if (this.receiver != null && this.registered) { try { this.cordova.getActivity().unregisterReceiver(this.receiver); + this.registered = false; } catch (Exception e) { Log.e(LOG_TAG, "Error unregistering network receiver: " + e.getMessage(), e); }