异步任务进度对话框显示为时已晚 [英] async task progress dialog show too late
本文介绍了异步任务进度对话框显示为时已晚的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
进度对话框出现,后期可能异步任务完成后,在doInBackground它调用Web服务和分析XML,活动要等待几秒钟,如果在XML是一个更大的文件
@覆盖
在preExecute保护无效(){
super.on preExecute();
完成= FALSE;
this.progressDialog.show();}@覆盖
保护布尔doInBackground(整数... PARAMS){
T = HttpHelper.callWebService(URL,的soapAction,XML);
如果(t.equals()){
返回false;
}
其他{
尝试{
SPF SAXParserFactory的= SAXParserFactory.newInstance();
的SAXParser SP = spf.newSAXParser();
XMLReader的XR = sp.getXMLReader();
XMLHelperFile myXmlHelperFile =新XMLHelperFile();
xr.setContentHandler(myXmlHelperFile);
InputSource的是=新的InputSource(新StringReader(CallWebFile.t));
xr.parse(是);
mesaj = myXmlHelperFile.getParsedData();
完成=真;
}赶上(例外五){
e.printStackTrace();
}
返回true;
}}@覆盖
保护无效onPostExecute(布尔结果){
super.onPostExecute(结果);
如果(完成==真&放大器;&安培; progressDialog.isShowing())progressDialog.dismiss();
}
@覆盖
保护无效onProgressUpdate(整数...值){
super.onProgressUpdate(值);
}
}
解决方案
只是一个猜测。初始化进度在preExecute对话框()
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);
}
}
解决方案
Just a guess. Initialize the progress dialog in preExecute()
这篇关于异步任务进度对话框显示为时已晚的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文