Reputation: 903
I have a AsyncTask in which an activity is launched during the doInBackground method:
private class startupTask extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... params) {
Intent intent = new Intent(StartupActivity.this, LoginConnectorActivity.class);
intent.putExtra("account", account);
startActivity(intent);
return null;
}
}
I want to wait for the called activity to finish before letting the AsyncTask finish. What would be the best way to do this?
Upvotes: 1
Views: 2233
Reputation: 83303
The question really is why would you ever do this?
The purpose of the AsyncTask
is to provide an easy means of performing a potentially expensive task so that it does not block the UI thread. From your question, it sounds like you could easily achieve your task without the use of multi-threading.
What you really want is to launch your Activity
with startActivityWithResult()
. Then start the new activity when the launched activity returns control to onActivityResult()
.
Upvotes: 3
Reputation: 8852
what you are asking beats the purpose of the AsyncTask
, as AsyncTask
suppose to run asynchronously with other tasks of the app and finish in the background. So if you want to wait while this task finishes then don't make it a AsyncTask
, as simple as that.
Upvotes: 3