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.
protected Void doInBackground(Integer... params) 
{
    onProgessUpdate("Contacting server..Please wait..");
    ...
}
Urrrm, nope, that won't work.
Try...
publishProgress("Contacting server..Please wait..");
You have to "publish" your progress in doInBackground(..) in order for onProgressUpdate(...) to be called.
Also don't call dialog.dismiss() in doInBackground(...) call it in onPostExecute(...) instead.
I think it should be..
publishProgress("Your Dialog message..");
not
onProgessUpdate("Processing the result"); 
in doInBack..()
Something like,
protected Long doInBackground(URL... urls) {
      publishProgress("Hello");
     return null;
 }
 protected void onProgressUpdate(String msg) {
     dialog.setMessage(msg);
 }
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With