进度对话框出现,可能在异步任务完成后延迟,在 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);
}
}