am using asynchronous task for hitting the web service url and retrieve the result from server but some time in onPreExecute() method if parsing exception occurs i handle it on catch() method,now i want to Halt the processing next means execution not go to OnpostExecute() method ,so how to stop execution process for going it to OnPostExecute()
my code are below
@Override
protected void onPreExecute() {
dialog = new ProgressDialog(MainMenu.this);
dialog.setMessage("Processing...");
dialog.setIndeterminate(true);
dialog.setCancelable(false);
dialog.show();
}
@Override
protected void onPostExecute(final Boolean success) {
if (dialog.isShowing())
{
dialog.dismiss();
}
Intent i = new Intent(MainMenu.this, filterpagetabs.class);
startActivity(i);
}
@Override
protected Boolean doInBackground(final String... args) {
try{
try {
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
XMLReader xr = sp.getXMLReader();
URL sourceUrl = new URL(
"http://www.mobi/iphonejh/output.php?estado=1");
MyXMLHandler myXMLHandler = new MyXMLHandler();
xr.setContentHandler(myXMLHandler);
xr.parse(new InputSource(sourceUrl.openStream()));
} catch (Exception e) {
System.out.println("XML Pasing Excpetion = " + e);
}
}
Put a parsingSuccessful boolean variable at the top with value true. In the catch of the parse exception set in on false. In the postExecute, use an if statement to check if the parsing has been successfully done and put the onPostExecute lines in this if statement.
Like this:
}