Because ... you're submitting your Callable
to the pool, then explicitly blocking the thread waiting for it to finish.
ArrayList<Notizia> notizie = task.get();
I missed the Android tag on your Q. You're re-inventing the wheel here. Android provides AsyncTask
for exactly this use case. See the AsyncTask example under Processes and Threads for an example of how it works.
(original answer follows)
You need your Callable
to update/notify the UI when it's finished. One possible approach would be to pass a reference to the list you mention to your Callable
.
Edit to add from comments:
Right now, you submit your Callable
to the pool. Then you sit there waiting for it to finish (blocking the UI thread). Then you do this:
lvListaNotizie.setAdapter(new RiempiLista(activity, notizie));
Pass lvListaNotizie
to your GetListaNotizie
via a constructor and have that happen at the end of call()
instead of returning the list to the Future
. I don't know what lvListaNotizie
is; if it's not thread-safe you will want to synchronize on it.