私のアプリケーションでは、htmlページをダウンロードして解析します。ただし、そのトラックでダウンロードを停止できるようにしたい(つまり、ユーザーがキャンセルを押したとき)。
これは私が現在使用しているコードであり、ASyncTaskのdoInBackgroundから呼び出されています。
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(urlstring);
URLConnection conn = url.openConnection();
TagNode node = cleaner.clean(new InputStreamReader(conn.getInputStream()));
return node;
} catch (Exception e) {
failed = true;
return;
}