【发布时间】:2024-01-05 05:48:01
【问题描述】:
我正在编写一个需要尽快响应的 Android 应用程序。该应用程序基本上从网站 (HTML, not XHTML) 获取内容,并使用 XPATH 查询解析其中的一些信息。我希望用户能够点击取消并中止请求,返回到上一个活动。
现在我的代码看起来像这样(我使用从http://htmlcleaner.sourceforge.net/ 到convert html to xhtml 的htmlcleaner jar):
//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;
}
我不确定我的代码中的下载是否真的可以中止,更不用说我知道如何完成这个了。我是在正确的道路上还是应该采取不同的方法?
【问题讨论】:
-
顺便说一句,我的代码工作正常,我只需要能够在用户点击“返回”时中止数据传输。
标签: android uri httprequest android-asynctask abort