]> average.org Git - WhereAmI.git/commitdiff
guard against leaving or double-unregistering the broadcast receiver
authorEugene Crosser <Eugene.Crosser@ru.ibm.com>
Mon, 30 Jan 2012 13:02:36 +0000 (17:02 +0400)
committerEugene Crosser <Eugene.Crosser@ru.ibm.com>
Mon, 30 Jan 2012 13:02:36 +0000 (17:02 +0400)
src/org/average/whereami/WhereAmI.java

index 2323f5421f0800c2d3c90175d432055144af8f4f..f3de41799e734b28e410bb6fa99bf8f39b91cd8b 100644 (file)
@@ -126,6 +126,7 @@ public class WhereAmI extends Activity
             IntentFilter intentFilter =
                 new IntentFilter("android.net.conn.CONNECTIVITY_CHANGE");
             registerReceiver(connChanged,intentFilter);
+            connChangedRegistered = true;
             boolean wifion = wifiman.setWifiEnabled(true);
             Log.w("WhereAmI", "enabling wifi result " + wifion);
             mHandler.postDelayed(resetInfo, 30000);
@@ -136,7 +137,10 @@ public class WhereAmI extends Activity
     private Runnable resetInfo = new Runnable () {
         public void run() {
             Log.w("WhereAmI", "resetInfo starting");
-            unregisterReceiver(connChanged);
+            if (connChangedRegistered) {
+                unregisterReceiver(connChanged);
+                connChangedRegistered = false;
+            }
             if (runningtasks > 0) {
                 for (int i = 0; i < ut.length; i++) {
                     ut[i].cancel();
@@ -151,6 +155,7 @@ public class WhereAmI extends Activity
         }
     };
 
+    private boolean connChangedRegistered = false;
     private final BroadcastReceiver connChanged = new BroadcastReceiver() {
         @Override
         public void onReceive(Context context, Intent intent) {
@@ -203,8 +208,7 @@ public class WhereAmI extends Activity
     public void onPause()
     {
         super.onPause();
-        Log.w("WhereAmI", "calling finish");
-        finish();
+        Log.w("WhereAmI", "going background");
     }
 
     /** Called when the activity is destroyed. */
@@ -216,7 +220,10 @@ public class WhereAmI extends Activity
        mHandler.removeCallbacks(updateClock);
        mHandler.removeCallbacks(updateCal);
        mHandler.removeCallbacks(updateInfo);
-        //unregisterReceiver(connChanged);
+        if (connChangedRegistered) {
+            unregisterReceiver(connChanged);
+            connChangedRegistered = false;
+        }
         boolean wifion = wifiman.setWifiEnabled(false);
         Log.w("WhereAmI", "disabling wifi result " + wifion);
     }