I have an AsyncTask that handles a rather long download, using HttpClient. I'd like to stop the execution of this request if the user finishes the Activity that starts it. How can I achieve this?
So I started the AsyncTask, HttpClient is in execute(), processing a GET request, is there a way to terminate this?
AsyncTask#cancel
to discard pending taskHttpUriRequest#abort()
to abort http request1.4. Aborting requests
In some situations HTTP request execution fails to complete within the expected time frame due to high load on the target server or too many concurrent requests issued on the client side. In such cases it may be necessary to terminate the request prematurely and unblock the execution thread blocked in a I/O operation. HTTP requests being executed by HttpClient can be aborted at any stage of execution by invoking HttpUriRequest#abort() method. This method is thread-safe and can be called from any thread. When an HTTP request is aborted its execution thread - even if currently blocked in an I/O operation - is guaranteed to unblock by throwing a InterruptedIOException
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With