async task progress dialog show too late

人盡茶涼 提交于 2019-12-23 19:04:34

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!