Note that there are some explanatory texts on larger screens.

plurals
  1. POCancel/abort a connection from the ThreadSafeClientConnManager connection pool
    text
    copied!<p>I'm using <a href="http://developer.android.com/reference/org/apache/http/impl/conn/tsccm/ThreadSafeClientConnManager.html" rel="nofollow noreferrer">ThreadSafeClientConnManager</a> to manage a <em>pool of client connections</em>, because my application has several threads, which are simultaneously connecting to a webserver.</p> <p>Abstract sample code: </p> <pre><code>HttpClient httpClient; ClientConnectionManager conMgr = new ThreadSafeClientConnManager(parameters,schReg); httpclient = new DefaultHttpClient(conMgr, parameters); </code></pre> <p>Now lets say on of this threads is downloading a large file, but then the user of my application is switching to another activity/screen. Therefor the file is needless and I'd like to abort this download connection.</p> <p>In <a href="http://developer.android.com/reference/org/apache/http/impl/conn/tsccm/ThreadSafeClientConnManager.html" rel="nofollow noreferrer">ThreadSafeClientConnManager</a> I found this method:</p> <p><code>public ClientConnectionRequest requestConnection (HttpRoute route, Object state)</code> Returns a new ClientConnectionRequest, from which a ManagedClientConnection can be obtained or the <strong>request can be aborted</strong>.</p> <p>So far I've been using:</p> <pre><code>HttpGet httpRequest = new HttpGet(URL_TO_FILE); HttpResponse response = (HttpResponse) httpclient.execute(httpRequest); [...] </code></pre> <p>Now from what I understand, I've to use:</p> <p><code>httpclient.getConnectionManager().requestConnection(HttpRoute route, Object state);</code></p> <p>And that's the point where I'm stuck. I assume that for the route I can just use <code>new HttpRoute(new HttpHost("10.0.0.1"))</code> or whatever my server is, but what to put in for <code>Object state</code>?</p> <p>And second, as soon as I've the <code>ClientConnectionManager</code> I can call <code>getConnection(long timeout, TimeUnit tunit)</code>. But then from there, how I do I execute my <code>HttpGet httpRequest = new HttpGet(URL_TO_FILE);</code> as I did before with <code>HttpResponse response = (HttpResponse) httpclient.execute(httpRequest);</code>?</p> <p>I've been gone through the documentation and tried out quite a few different things, but I wasn't able to obtain a working solution. Therefor any suggestions and/or code examples are more than welcome.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload