I have created an async task and want to change the message of progress dialog during different stages of doBackground. Here is the code:
public class sc extends AsyncTask<Integer,String,Void>
{
ProgressDialog dialog;
protected void onPreExecute()
{
dialog=new ProgressDialog(Loc.this);
dialog.show();
}
@Override
protected Void doInBackground(Integer... params)
{
onProgressUpdate("Contacting server..Please wait..");
//Do some work
onProgressUpdate("Processing the result");
//Do some work
onProgressUpdate("Calculating..");
dialog.dismiss();
return null;
}
protected void onProgressUpdate(String ui)
{
dialog.setMessage(ui);
}
}
But the problem is that, progress dialog is only showing the first message always. Kindly help me to find a solution.
Urrrm, nope, that won’t work.
Try…
You have to “publish” your progress in
doInBackground(..)in order foronProgressUpdate(...)to be called.Also don’t call
dialog.dismiss()indoInBackground(...)call it inonPostExecute(...)instead.