【问题标题】:async task progress dialog show too late异步任务进度对话框显示太晚
【发布时间】:2012-11-21 14:35:59
【问题描述】:

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


    }
}

【问题讨论】:

    标签: android asynchronous task progressdialog


    【解决方案1】:

    只是猜测。在 preExecute() 中初始化进度对话框

    【讨论】:

    • 被初始化时调用函数 public CallWebFile(ProgressDialog progressDialog, Integer Id) { this.progressDialog = progressDialog; id=Id;
    【解决方案2】:

    您在 doInBackground() 中缺少以 publishProgress(some int value); 形式调用 publishProgress

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多