0

Look at code snippet below from my SetupActivity - how can I test that the task I fired here actually executed correctly?

For example this line:

new AttachChildGcmTask(app).execute(app.getChildInfo().getId());

Code snippet from my Activity:

....
@Override
public void onClick(View v) {
    if (v.getId() == R.id.btn_proceed) {
        finishSetup();
    }
}


private void finishSetup() {
    UIUtilities.showToast(this, R.string.setup_completed, true);
    final AppBipper app = (AppBipper) getApplication();
    app.setSetupCompleted(true);

    Log.i(TAG, "finishSetup childId: "+app.getChildInfo().getId());
    new AttachChildGcmTask(app).execute(app.getChildInfo().getId());
    Log.i(TAG, "download settings");
    new FetchClientSettings(app).execute();

    Log.i(TAG, "cancel all scheduled alarms");
    ScheduledLocationsHelper helper =
            ScheduledLocationsHelper.getInstance(app.getDBManager(), app);
    helper.cancelAlarms();

    startActivity(new Intent(this, StartupActivity.class));
    finish();
}
Vit Khudenko
  • 28,288
  • 10
  • 63
  • 91
Thomas Vervik
  • 4,325
  • 9
  • 36
  • 64

2 Answers2

1

Check this out, it'll probably help:

Is AsyncTask really conceptually flawed or am I just missing something?

Community
  • 1
  • 1
Flávio Faria
  • 6,575
  • 3
  • 39
  • 59
0

I guess you mean that the activity dies before the tasks are completed.

So include those tests inside your AsyncTask class and have them report to your UI somehow (Broadcasting an intent, using an handler and so on...)

Jong
  • 9,045
  • 3
  • 34
  • 66