试图从Android应用程序的网站下载信息?

时间:2012-05-29 23:21:52

标签: android

我开始一项活动,我在创建

中调用此下载方法
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它是否有效,如果线程没有启动?我怎样才能从网站上下载信息?

1 个答案:

答案 0 :(得分:0)

通常在Android中执行异步任务的正确方法是实现扩展AsyncTask的任务。