Using Asynctask To Start Activity
I am using asyncTask to show Dialog and then after few minutes then launch a new activity. unfortunately that activity start before task finished ??? package com.android.grad; imp
Solution 1:
Yes, you can start activity from AsyncTask's sub class. See below:
@OverrideprotectedvoidonPostExecute(Boolean result) {
Toast.makeText(activity, Boolean.toString(result), Toast.LENGTH_LONG).show();
activity.startActivity(newIntent(activity, BuiltInCamera.class));
}
After making this change, make sure you do remove startActivity from OnClickListener
Solution 2:
Call this startActivity(new Intent(LoginActivity.this, BuiltInCamera.class));
from onPostExecute()
after Displaying toast message.
In this way, new activity will be called after your AsyncTask
is over.
Solution 3:
You can also use
Intent intent = newIntent(activity, PageViewActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
activity.getApplicationContext().startActivity(intent);
Solution 4:
Call startActivity
inside onPostExecute
method of AsyncTask
Post a Comment for "Using Asynctask To Start Activity"