2011-02-03 5 views
1

가능한 한 빨리 대응해야하는 Android 용 애플리케이션을 작성 중입니다. 앱은 기본적으로 웹 사이트 (HTML, not XHTML)의 콘텐츠를 가져 와서 XPATH 개의 검색어를 사용하여 일부 정보를 구문 분석합니다. 사용자가 취소를 눌러 요청을 중단하고 이전 활동으로 돌아갈 수 있기를 바랍니다.Android에서 중단 된 프로세스로 웹 페이지 가져 오기. 가장 반응이 빠른 방법은 무엇입니까?

지금 내 코드 (나는 http://htmlcleaner.sourceforge.net/에서 convert html to xhtml에 htmlcleaner 항아리를 사용) 다음과 같습니다

//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; 
    } 

내 코드에서 다운로드가 내가 아는 것이라고 말할 것도없고, 실제로 abortable 경우 확실하지 않다 이것을 성취하는 방법. 나는 바른 길에 있습니까? 아니면 다른 접근 방식을 취해야합니까?

+0

Btw, 내 코드는 정상적으로 작동하지만 사용자가 '뒤로'를 치면 데이터 전송을 중단 할 수 있어야합니다. –

답변

0

이 문제를 해결했습니다. ASyncTask 사용에 대한 자세한 내용은이 게시물을 참조하십시오. Android stop download