3

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);


    }
}

2 Answers2

1

Just a guess. Initialize the progress dialog in preExecute()

arjoan
  • 1,849
  • 2
  • 20
  • 39
  • is initialized whed call function public CallWebFile(ProgressDialog progressDialog, Integer Id) { this.progressDialog = progressDialog; id=Id; – user1269301 Nov 21 '12 at 15:09
0

You are missing a call to publishProgress as publishProgress(some int value); inside your doInBackground()

Robin Chander
  • 7,225
  • 3
  • 28
  • 42