I have a list of items on which user can click for download. For which I am having this code:
//Maintained this in my ListAdapter class so that if user clicks on cancel download i can do:
// tasks.get(info.getFieldID()).cancel(true);
public static Map<String, Future<Object>> tasks = new HashMap<String, Future<Object>>();
Future f = downloadExecutor.submit(new Callable<Object>() {
// do downloading.
}
tasks.put(key,f);
I am trying to cancel this the respective download when user clicks on cancel by calling tasks.get(key).cancel(true);
But my task is not getting cancelled.
Few questions:
Am I doing anything wrong by maintaining the list of future objects in the adapter class ?
How should i get a task to get cancelled when user clicks on a button?
Also how do i know that the task has been cancelled?
I have read about ExecutorService but I am little confused about the implementation.