1

我正在为需要尽快响应的 Android 编写应用程序。该应用程序基本上从网站 ( ) 中获取内容,并使用查询HTML, not XHTML解析其中的一些信息。XPATH我希望用户能够点击取消并中止请求,返回到上一个活动。

现在我的代码看起来像这样(我使用来自http://htmlcleaner.sourceforge.net/的 htmlcleaner jar到convert html to xhtml):

   //this is called from the doInBackground() method embedded in an ASyncTask
   HtmlCleaner cleaner = new HtmlCleaner();
   CleanerProperties props = cleaner.getProperties();
   props.setAllowHtmlInsideAttributes(true);
   props.setAllowMultiWordAttributes(true);
   props.setRecognizeUnicodeChars(true);
   props.setOmitComments(true);
   try {
        URL url = new URL("---my-url-goes-here---");
        URLConnection conn = url.openConnection();
        TagNode node = cleaner.clean(new InputStreamReader(conn.getInputStream()));
        return node;
   } catch (Exception e) {
       failed = true;
   }

我不确定我的代码中的下载是否真的可以中止,更不用说我知道如何完成这个了。我是在正确的道路上还是应该采用不同的方法?

4

1 回答 1

0

我已经解决了这个问题,有关使用 ASyncTask 的更多信息,请参阅这篇文章。安卓停止下载

于 2011-03-24T18:28:09.550 回答