I have one Thread Safe HttpClient for the whole application, and I have a Service and an Activity that are making a various REST API calls very frequently in separate Threads. And sometimes it comes to the point where I need to cancel a started HttpRequest, because I already need to start another with an updated data. I don't want to make user wait for the first request to finish, and then wait for the second one, and maybe at this point user will update the data again and I'll need to call the third request. So what I want to do is cancel request with an old data and start a new one. I tried cancelling the AsyncTask, but for some reason it doesn't cancel the started request. Here's my code:
if (getAlbumImage != null && getAlbumImage.getStatus() == AsyncTask.Status.RUNNING) {
Log.d(VibesApplication.VIBES, "cancelling image loader");
getAlbumImage.cancel(true);
}
getAlbumImage = new GetAndSetAlbumImage();
getAlbumImage.execute(performer, name);
Also I tried shutting down the connection manager. as suggested here: https://stackoverflow.com/a/7311393/1032286 But I have only one client and manager, I don't want to create them every time I make a REST call. What should I do? I would be glad if there's a way to cancel all running requests, but if there's a way to cancel separate ones, that would be neat.