cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agri...@apache.org
Subject cordova-plugin-network-information git commit: CB-7976 Android: Use webView's context rather than Activity's context for intent receiver
Date Thu, 06 Nov 2014 21:25:51 GMT
Repository: cordova-plugin-network-information
Updated Branches:
  refs/heads/master 9dc1796c5 -> 165b4f012


CB-7976 Android: Use webView's context rather than Activity's context for intent receiver


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-network-information/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-network-information/commit/165b4f01
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-network-information/tree/165b4f01
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-network-information/diff/165b4f01

Branch: refs/heads/master
Commit: 165b4f01209e6cbdb83619c2b1fb1b860cc1dccc
Parents: 9dc1796
Author: Andrew Grieve <agrieve@chromium.org>
Authored: Thu Nov 6 16:21:52 2014 -0500
Committer: Andrew Grieve <agrieve@chromium.org>
Committed: Thu Nov 6 16:21:52 2014 -0500

----------------------------------------------------------------------
 src/android/NetworkManager.java | 19 +++++--------------
 1 file changed, 5 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-network-information/blob/165b4f01/src/android/NetworkManager.java
----------------------------------------------------------------------
diff --git a/src/android/NetworkManager.java b/src/android/NetworkManager.java
index 1b2656e..4c85dda 100755
--- a/src/android/NetworkManager.java
+++ b/src/android/NetworkManager.java
@@ -76,20 +76,12 @@ public class NetworkManager extends CordovaPlugin {
     private static final String LOG_TAG = "NetworkManager";
 
     private CallbackContext connectionCallbackContext;
-    private boolean registered = false;
 
     ConnectivityManager sockMan;
     BroadcastReceiver receiver;
     private JSONObject lastInfo = null;
 
     /**
-     * Constructor.
-     */
-    public NetworkManager() {
-        this.receiver = null;
-    }
-
-    /**
      * Sets the context of the Command. This can then be used to do things like
      * get file paths associated with the Activity.
      *
@@ -113,8 +105,7 @@ public class NetworkManager extends CordovaPlugin {
                         updateConnectionInfo(sockMan.getActiveNetworkInfo());
                 }
             };
-            cordova.getActivity().registerReceiver(this.receiver, intentFilter);
-            this.registered = true;
+            webView.getContext().registerReceiver(this.receiver, intentFilter);
         }
 
     }
@@ -148,12 +139,13 @@ public class NetworkManager extends CordovaPlugin {
      * Stop network receiver.
      */
     public void onDestroy() {
-        if (this.receiver != null && this.registered) {
+        if (this.receiver != null) {
             try {
-                this.cordova.getActivity().unregisterReceiver(this.receiver);
-                this.registered = false;
+                webView.getContext().unregisterReceiver(this.receiver);
             } catch (Exception e) {
                 Log.e(LOG_TAG, "Error unregistering network receiver: " + e.getMessage(),
e);
+            } finally {
+                receiver = null;
             }
         }
     }
@@ -273,4 +265,3 @@ public class NetworkManager extends CordovaPlugin {
         return TYPE_UNKNOWN;
     }
 }
-


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


Mime
View raw message