できるだけ早く応答する必要がある Android 用のアプリケーションを作成しています。このアプリは基本的に、Web サイト ( ) からコンテンツを取得し、クエリ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;
}
私のコードでのダウンロードが実際に中止可能かどうかはわかりませんが、これを達成する方法を知っていることは言うまでもありません。私は正しい道を進んでいますか、それとも別のアプローチをとるべきですか?