- public TextView tv;
- public Integer updater; // will be the function/object
- public UpdateTarget(TextView tv, Integer updater) {
- this.tv = tv;
- this.updater = updater;
+ private TextView tv;
+ private Oracle updater;
+ private BgUpdate task;
+
+ private class BgUpdate extends AsyncTask<Void, Void, String> {
+ @Override
+ protected String doInBackground(Void... params) {
+ Log.v(TAG, "BgUpdate " + updater + " starting");
+ return updater.getResult();
+ }
+
+ @Override
+ protected void onPostExecute(String str) {
+ Log.v(TAG, "BgUpdate callback executing");
+ tv.setText(str);
+ runningtasks--;
+ if (runningtasks <= 0) {
+ if (managewifi) {
+ boolean wifion = wifiman.setWifiEnabled(false);
+ Log.v(TAG, "disabling wifi result " + wifion);
+ }
+ Time tm = new Time();
+ tm.setToNow();
+ tvs.setText(R.string.lasttry);
+ tvs.append(tm.format(" %d/%m/%Y %H:%M"));
+ }
+ }
+
+ @Override
+ protected void onCancelled() {
+ Log.v(TAG, "BgUpdate callback cancelled");
+ runningtasks--;
+ }
+ }
+
+ public UpdateTarget(TextView tv, Oracle updater) {
+ this.tv = tv;
+ this.updater = updater;
+ }
+
+ public void launch() {
+ tv.setText(R.string.updating);
+ task = new BgUpdate();
+ task.execute();
+ }
+
+ public void cancel() {
+ task.cancel(true);