private Integer runningtasks = 0;
private class UpdateTarget {
- public TextView tv;
- public Integer updater; // will be the function/object
+ private TextView tv;
+ private Integer updater; // will be the function/object
+ private BgUpdate task;
+
+ private class BgUpdate extends AsyncTask<Void, Void, String> {
+ @Override
+ protected String doInBackground(Void... params) {
+ Log.w("WhereAmI", "BgUpdate " + updater + " starting");
+ SystemClock.sleep(5000); // real job do be done here
+ Log.w("WhereAmI", "BgUpdate about to return");
+ return "5 seconds passed in " + updater;
+ }
+
+ @Override
+ protected void onPostExecute(String str) {
+ Log.w("WhereAmI", "BgUpdate callback executing");
+ tv.setText(str);
+ runningtasks--;
+ if (runningtasks <= 0) {
+ boolean wifion = wifiman.setWifiEnabled(false);
+ Log.w("WhereAmI", "disabling wifi result " + wifion);
+ Time tm = new Time();
+ tm.setToNow();
+ tvs.setText(R.string.lasttry);
+ tvs.append(tm.format(" %d/%m/%Y %H:%M:%S"));
+ }
+ }
+ }
+
public UpdateTarget(TextView tv, Integer updater) {
- this.tv = tv;
- this.updater = updater;
+ this.tv = tv;
+ this.updater = updater;
+ this.task = new BgUpdate();
+ }
+
+ public void launch() {
+ tv.setText(R.string.updating);
+ task.execute();
}
}
private UpdateTarget[] ut;
boolean wifion = wifiman.setWifiEnabled(true);
Log.w("WhereAmI", "enabling wifi result " + wifion);
mHandler.postDelayed(resetInfo, 30000);
- mHandler.postDelayed(this, 60000);
+ mHandler.postDelayed(this, 1200000);
}
};
if (isConnected) {
for (int i = 0; i < ut.length; i++) {
runningtasks++;
- ut[i].tv.setText(R.string.updating);
- new BgUpdate().execute(ut[i]);
+ ut[i].launch();
}
}
}
};
- private class BgUpdate extends AsyncTask<UpdateTarget, Void, String> {
- private UpdateTarget ut;
- @Override
- protected String doInBackground(UpdateTarget... whereto) {
- Log.w("WhereAmI", "BgUpdate starting");
- ut = whereto[0];
- SystemClock.sleep(5000); // real job do be done here
- Log.w("WhereAmI", "BgUpdate about to return");
- return "5 seconds passed";
- }
-
- @Override
- protected void onPostExecute(String str) {
- Log.w("WhereAmI", "BgUpdate callback executing");
- ut.tv.setText(str);
- runningtasks--;
- if (runningtasks <= 0) {
- boolean wifion = wifiman.setWifiEnabled(false);
- Log.w("WhereAmI", "disabling wifi result " + wifion);
- Time tm = new Time();
- tm.setToNow();
- tvs.setText(R.string.lasttry);
- tvs.append(tm.format(" %d/%m/%Y %H:%M:%S"));
- }
- }
- }
-
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onPause();
Log.w("WhereAmI", "calling finish");
- this.finish();
+ finish();
}
/** Called when the activity is destroyed. */