I have asynktask that shows a progressDialog and update its value in doInBackground method. the methods code:
@Override
protected void onPreExecute() {
progress = new ProgressDialog(cont);
progress.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progress.setIndeterminate(true);
progress.setTitle(cont.getResources().getString(R.string.pleaseWait));
progress.setMessage(cont.getResources().getString(R.string.loadingImages));
progress.show();
super.onPreExecute();
}
@Override
protected String doInBackground(Void... arg0) {
progress.setProgress(2);
//do some work on the database and network
progress.setProgress(25);
//Do some extra work
for(int i = 0; i < itemImagesList.size(); i++){
publishProgress((int) ((i / (float) itemImagesList.size()) * 100));
//Do somework
}
}
@Override
protected void onProgressUpdate(Integer... prog) {
progress.setProgress(prog[0]);
}
@Override
protected void onPostExecute(String result) {
progress.dismiss();
super.onPostExecute(result);
}
The progressDialog value doesn't change at all! and if I tried to set the dialog message using:
progress.setMessage("At item "+i);
some exception occurs if I put it in the middle of the method, but in the first it works fine!
what's wrong?