Showing Progressdialog On Asyncthread Android
I want to show a ProgressDialog when a call to a Web Service call is made, this is my code: public class penAPIController extends AsyncTask
Solution 1:
Based on the comments, you are calling get()
on the AsyncTask
. This will block the submitting thread (main UI thread in your case) until the async task result is available, that is, doInBackground()
returns.
Remove the call to get()
and handle the completion e.g. in onPostExecute()
or using a callback function.
Solution 2:
privateProgressDialog progressDialog; // class variable privatevoidshowProgressDialog(String title, String message)
{
progressDialog = newProgressDialog(this);
progressDialog.setTitle(""); //title
progressDialog.setMessage(""); // message
progressDialog.setCancelable(false);
progressDialog.show();
}
onPreExecute()
protectedvoidonPreExecute()
{
showProgressDialog("Please wait...", "Your message");
}
Check and dismiss onPostExecute() -
protectedvoidonPostExecute()
{
if(progressDialog != null && progressDialog.isShowing())
{
progressDialog.dismiss();
}
}
Post a Comment for "Showing Progressdialog On Asyncthread Android"