From: Eugene Crosser Date: Mon, 30 Jan 2012 13:02:36 +0000 (+0400) Subject: guard against leaving or double-unregistering the broadcast receiver X-Git-Url: http://average.org/gitweb/?a=commitdiff_plain;h=69b322114a2b66c1c3751d7414f2be525d301f65;p=WhereAmI.git guard against leaving or double-unregistering the broadcast receiver --- diff --git a/src/org/average/whereami/WhereAmI.java b/src/org/average/whereami/WhereAmI.java index 2323f54..f3de417 100644 --- a/src/org/average/whereami/WhereAmI.java +++ b/src/org/average/whereami/WhereAmI.java @@ -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); }