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 に答える