I’ve figured out why it crashed sometimes it couldnt get the url and askctask just kept working the background how do i set a interval for opening a url rock.open stream is where it really slow down i want he user to try again later and stop asynctask after a certain amount of time or make asynctask restart because ok if i turn offf wifi ofcourse app crashes?
on create.....(
ws=new WeatherSet();
new DownloadImageTask().execute(queryString);
if set a debug point here works magically :)
private class DownloadImageTask extends AsyncTask<String, Void, String> {
protected String doInBackground(String... urls) {
try {
URL rock=new URL(urls[0]);
/* Get a SAXParser from the SAXPArserFactory. */
SAXParserFactory spf =
SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
/* Get the XMLReader of the SAXParser we created.
XMLReader xr = sp.getXMLReader();
/*
* Create a new ContentHandler and apply it to the
* XML-Reader
*/
WeatherHandler gwh = new
WeatherHandler();
xr.setContentHandler(gwh);
/* Parse the xml-data our URL-call returned. */
xr.parse(new InputSource(rock.openStream()));
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return "";
}
protected void onPostExecute(String result) {
weather();
}
It happens when your activity need some objects to be initialize and that thing happens in backgroung thread,
Error occurs because, Thread haven’t completed its task and activity comes alive. And the objects that are suppose to initialize by bg thread is not done yet.
You need to identify that objects and perform operation after postExecution of the Asynctast.
In debug it is working perfectly because, You have put break-point in activity, not in thread. so the Thread will complete its task and object get initialized.
Hope this help!!