In my app I'd like to handle downloading of several files at the same time. To do so I'm starting several services, one for each request. As I'm not sure, does Android support simultaneous http requests in parallel?
In that case, is it good or bad habit to have one HTTPClient per request?
Many thanks for your help!
HttpClient is not asynchronous and does not support parallel connections per se. You could have multiple threads each performing download with separate HttpClient instances.
You might also want to look at ExecutorService: http://developer.android.com/reference/java/util/concurrent/ExecutorService.html
When equipped with a pooling connection manager such as ThreadSafeClientConnManager
, HttpClient
can be used to execute multiple requests simultaneously using multiple threads of execution.
Here is a full example on how to use it: 2.9. Multithreaded request execution.
Update: It took a while, but the ThreadSafeClientConnManager
is now deprecated (see excerpt below from Apache Http Client Removal):
Android 6.0 release removes support for the Apache HTTP client. If your app is using this client and targets Android 2.3 (API level 9) or higher, use the HttpURLConnection class instead. This API is more efficient because it reduces network use through transparent compression and response caching, and minimizes power consumption.
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