Issue
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.
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.
Answered By - Squonk
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.