]> www.average.org Git - WhereAmI.git/blobdiff - src/org/average/whereami/WhereAmI.java
catch cancellation
[WhereAmI.git] / src / org / average / whereami / WhereAmI.java
index 5a665d1ed02346e3eae46830b3ebf9558eef60dd..988f1fb53149b88be2f366ce151d50483db5e3e6 100644 (file)
@@ -53,18 +53,28 @@ public class WhereAmI extends Activity
                     tvs.append(tm.format(" %d/%m/%Y %H:%M:%S"));
                 }
             }
+
+            @Override
+            protected void onCancelled() {
+                Log.w("WhereAmI", "BgUpdate callback cancelled");
+                runningtasks--;
+            }
         }
 
         public UpdateTarget(TextView tv, Integer updater) {
             this.tv = tv;
             this.updater = updater;
-            this.task = new BgUpdate();
         }
 
         public void launch() {
             tv.setText(R.string.updating);
+            task = new BgUpdate();
             task.execute();
         }
+
+        public void cancel() {
+            task.cancel(true);
+        }
     }
     private UpdateTarget[] ut;
 
@@ -116,7 +126,7 @@ public class WhereAmI extends Activity
             boolean wifion = wifiman.setWifiEnabled(true);
             Log.w("WhereAmI", "enabling wifi result " + wifion);
             mHandler.postDelayed(resetInfo, 30000);
-            mHandler.postDelayed(this, 1200000);
+            mHandler.postDelayed(this, 60000);
         }
     };
 
@@ -124,14 +134,17 @@ public class WhereAmI extends Activity
         public void run() {
             Log.w("WhereAmI", "resetInfo starting");
             unregisterReceiver(connChanged);
-            boolean wifion = wifiman.setWifiEnabled(false);
-            Log.w("WhereAmI", "disabling wifi result " + wifion);
             if (runningtasks > 0) {
+                for (int i = 0; i < ut.length; i++) {
+                    ut[i].cancel();
+                }
                 Time tm = new Time();
                 tm.setToNow();
                 tvs.setText(R.string.failtry);
                 tvs.append(tm.format(" %d/%m/%Y %H:%M:%S"));
             }
+            boolean wifion = wifiman.setWifiEnabled(false);
+            Log.w("WhereAmI", "disabling wifi result " + wifion);
         }
     };