I don't understand why I'm getting this error. I'm using AsyncTask to run some processes in the background.
I have:
protected void onPreExecute()
{
connectionProgressDialog = new ProgressDialog(SetPreference.this);
connectionProgressDialog.setCancelable(true);
connectionProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
connectionProgressDialog.setMessage("Connecting to site...");
connectionProgressDialog.show();
downloadSpinnerProgressDialog = new ProgressDialog(SetPreference.this);
downloadSpinnerProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
downloadSpinnerProgressDialog.setMessage("Downloading wallpaper...");
}
When I get into doInBackground()
depending on a condition I:
[...]
connectionProgressDialog.dismiss();
downloadSpinnerProgressDialog.show();
[...]
Whenever I try downloadSpinnerProgressDialog.show()
I receive the error.
Any ideas guys?
I had a similar issue but from reading this question I figured I could run on UI thread:
Seems to do the trick for me.
The method
show()
must be called from the User-Interface (UI) thread, whiledoInBackground()
runs on different thread which is the main reason whyAsyncTask
was designed.You have to call
show()
either inonProgressUpdate()
or inonPostExecute()
.For example:
I had a hard time making this work too, the solution for me was to use both hyui and konstantin answers,