0

从我的 SetupActivity 中查看下面的代码片段 - 我如何测试我在此处触发的任务是否正确执行?

例如这一行:

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

我的活动中的代码片段:

....
@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();
}
4

2 回答 2

1

看看这个,它可能会有所帮助:

AsyncTask 真的在概念上存在缺陷还是我只是遗漏了什么?

于 2012-11-12T21:15:21.007 回答
0

我猜你的意思是活动在任务完成之前就结束了。

因此,将这些测试包含您的AsyncTask类中,并让它们以某种方式向您的 UI 报告(广播意图,使用处理程序等等......)

于 2012-11-12T21:15:24.820 回答