android – AsyncTask with a ProgressDialog and Progress Bar-ThrowExceptions

Exception or error:

I am attempting to use AsyncTask to load a file of determinate length. My AsyncTask looks something like this:

protected void onPreExecute() {
    dialog =, null, "Loading", false);

protected void onProgressUpdate(Integer... values) {
    if (values.length == 2) {

in my doInBackground() implementation I call publishProgress(bytesSoFar, maxBytes); inside my loading loop and in the onPostExecute() I call dialog.dismiss().

However, I can’t get the ProgressDialog to show anything but an indeterminate spinner. I want to see a horizontal progress bar that shows the progress as the loading happens. I’ve debugged and can see that onProgressUpdate() gets called with sane values and that the dialog’s methods are getting called.

How to solve:

Add Style to your progress dialog with before you show it .setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);


Use this code in your onPreExecute().

 ProgressDialog prog;
 prog = new ProgressDialog(ctx);

Leave a Reply

Your email address will not be published. Required fields are marked *