进度对话框似乎很晚,可能在异步任务完成之后,在doinbackground中它调用web服务并解析xml,如果在xml中是一个更大的文件,则活动必须等待几秒钟
@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);
}
}
最佳答案
只是一个猜测。在preexecute()中初始化进度对话框
关于android - 异步任务进度对话框显示为时已晚,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13495547/