我开始一项活动,我在创建
中调用此下载方法public void download(){
thread = new Runnable () {
public void run() {
try{
/* 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 GoogleWeatherHandler();
xr.setContentHandler(gwh);
/* Parse the xml-data our URL-call returned. */
temp////is a url defined
xr.parse(new InputSource(temp.openStream()));
ws = gwh.getWeatherSet();
}
catch(Exception e){
}
}new Thread(thread).start();
}
问题是,如果我调试并实际越过行thread.start
它是否有效,如果线程没有启动?我怎样才能从网站上下载信息?
答案 0 :(得分:0)
通常在Android中执行异步任务的正确方法是实现扩展AsyncTask
的任务。