I try to open the 2nd activity which require some time to load data from internet first from main activity, during this period, my screen will full in black, so i decide to use progress dialog to show “hey, I’M STILL alive, DON’T CLOSE ME!”
Everything went perfectly but the only problem is that the spinner is not rotating. here is my code:
after button is click: new YourAsyncTask().execute();
public class YourAsyncTask extends AsyncTask<Void, Void, Void> {
private ProgressDialog myDialog;
@Override
protected void onPreExecute() {
//show your dialog here
myDialog = ProgressDialog.show(ScrollingTab.this, "loading..", "please wait..", true, true);
myDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
}
@Override
protected Void doInBackground(Void... params) {
//update your DB - it will run in a different thread
startActivity(new Intent("com.android.ricky.RESULT_DETAIL"));
return null;
}
@Override
protected void onPostExecute(Void result) {
//hide your dialog here
myDialog.dismiss();
}
}
I have tried to remove ” startActivity(new Intent(“com.android.ricky.RESULT_DETAIL”));” and “myDialog.dismiss();” at the same time, then the spinner is rotating ><
please help, thanks a lot!
Your concept is little bit confusing and wrong,
You have to start 2nd Activity on button’s click and then
onCreate()of your 2nd Activity execute theYourAsyncTask(). And download data from internet for 2nd Activity indoInBackground()ofAsyncTask. After complete the download prepare your UI for 2nd Activity inonPostExecute()ofAsyncTaskand thendismiss()theProgressDialog.