问题
progress dialog appear to, late probably after async task is finished,in doInBackground it calls a web service and parse an xml,the activity have to wait for some seconds if in xml is a bigger file
@Override
protected void onPreExecute(){
super.onPreExecute();
completed=false;
this.progressDialog.show();
}
@Override
protected Boolean doInBackground(Integer... params) {
t=HttpHelper.callWebService( url, soapAction,xml);
if (t.equals("")){
return false;
}
else {
try {
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
XMLReader xr = sp.getXMLReader();
XMLHelperFile myXmlHelperFile = new XMLHelperFile();
xr.setContentHandler(myXmlHelperFile);
InputSource is = new InputSource(new StringReader(CallWebFile.t));
xr.parse(is);
mesaj = myXmlHelperFile.getParsedData();
completed=true;
} catch (Exception e) {
e.printStackTrace();
}
return true;
}
}
@Override
protected void onPostExecute(Boolean result) {
super.onPostExecute(result);
if (completed==true && progressDialog.isShowing()) progressDialog.dismiss();
}
@Override
protected void onProgressUpdate(Integer... values) {
super.onProgressUpdate(values);
}
}
回答1:
Just a guess. Initialize the progress dialog in preExecute()
回答2:
You are missing a call to publishProgress as publishProgress(some int value);
inside your doInBackground()
来源:https://stackoverflow.com/questions/13495547/async-task-progress-dialog-show-too-late