I am not able to run a ProgressDialog inside the doInBackground method of AsyncTask. It gives me the following error:
ERROR/AndroidRuntime(12986): Caused by: java.lang.RuntimeException: Can’t create handler inside thread that has not called Looper.prepare()
And the error is on this line in the code:
final ProgressDialog dialog = ProgressDialog.show(GalleryView.this, "Refresh", "Loading... please wait", true);
Any help much appreciated.
You can show the progressdialog in the onPreExecute method and dismiss it in the onPostExecute method. These two methods run in the UI thread. The doInBackGround method runs in another thread.
Another possibility is to just show the progressdialog before you start the AsyncTask. Personally I like the option to use onPreExecute and onPostExecute. The progressdialog is then linked nicely to the AsyncTask.