我已经弄清楚为什么它有时会崩溃,它无法获取 url,而 askctask 只是继续在后台工作我如何设置打开 url 的时间间隔 rock.open 流是它真正减慢的地方我希望他用户稍后再试一次在一定时间后停止 asynctask 或让 asynctask 重新启动,因为如果我关闭 wifi,当然应用程序崩溃了?
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();
}