简体   繁体   中英

progressbar in asynctask not getting in onProgressUpdate

My asynctask not going in onProgressUpdate. why? I'm going to create progress bar in asynctask. Below is my code to show uploading image by using progress bar.

public static class RegisterDataEngineForPost extends AsyncTask<MultipartEntity, integer, String>{


    ProgressBar ProgressBarUpload;


    public void setmCurrentPhotoPath(ProgressBarUploadb) {

        ProgressBarUpload = ProgressBarUploadb;
    }

    @Override
    protected void onProgressUpdate(integer... values) {


    }

    @Override
    protected void onPreExecute() {
        ProgressBarUpload.setProgress(0);
    }


    @Override
    protected String doInBackground(MultipartEntity... params) {


    }

    @Override
    protected void onPostExecute(String result) {

        }
    }
}

Use http://developer.android.com/reference/android/os/AsyncTask.html#publishProgress(Progress...)

manually, Android will not know your progress out of nothing, you need to determine it yourself.

You have to call publishProgress(progress_value) to update the progress like that

public static class RegisterDataEngineForPost extends AsyncTask<MultipartEntity, integer, String>{


ProgressBar ProgressBarUpload;


public void setmCurrentPhotoPath(ProgressBarUploadb) {

    ProgressBarUpload = ProgressBarUploadb;
}

@Override
protected void onProgressUpdate(integer... values) {


}

@Override
protected void onPreExecute() {
    ProgressBarUpload.setProgress(0);
}


@Override
protected String doInBackground(MultipartEntity... params) {
      //do some task and update the progress
   publishProgress(progress_value);

}

@Override
protected void onPostExecute(String result) {

    }
}
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM