Jsoup를 사용하여 웹 페이지를 다운로드하고 구문 분석하여 목록에 콘텐츠를 표시했습니다. 이 프로세스는 어느 정도 시간이 걸리기 때문에 다른 스레드에서 작업을 수행하고 결과를 다시 얻으려면 Callable 인터페이스를 구현했습니다. 문제는 프로세스 중에 여전히 UI를 차단한다는 것입니다.호출 가능 차단 UI
public class GetListaNotizie implements Callable<ArrayList<Notizia>> {
static ArrayList<Notizia> getNotizieBySezione() {
[...] Long process
return notizie;
}
@Override
public ArrayList<Notizia> call() throws Exception {
return getNotizieBySezione();
}
}
: 그리고
final ExecutorService service;
final Future<ArrayList<Notizia>> task;
service = Executors.newFixedThreadPool(1);
task = service.submit(new GetListaNotizie());
try {
ArrayList<Notizia> notizie = task.get();
lvListaNotizie.setAdapter(new RiempiLista(activity, notizie));
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
나는 무엇을 놓치고?
'task.get()'호출이 차단 중입니다. 어쨌든, 유언 집행자와 선물을 사용하여 바퀴를 재발 명할 필요가 없습니다. 안드로이드는 이미 이러한 종류의 작업을 위해 * 정확하게 [* AsyncTask'] (http://developer.android.com/reference/android/os/AsyncTask.html) 클래스를 가지고 있습니다. –