I have a GridView with many ImageView items. For each of the item I lazy load a thumbnail imahge from WebService using HttpClient. I crate a new HttpClient for every image i download. The thumbnails are 2-4kB small. I noticed the download is slow, images are loaded 1 by 1 and each of them is downloaded in 1s. Is it possible to speed up the process?
public Bitmap downloadPhoto( String url ) {
try {
HttpParams params = new BasicHttpParams();
params.setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
HttpClient client = new DefaultHttpClient(params);
HttpUriRequest request = new HttpGet(url);
if ( this.authToken != null ) {
request.setHeader(AUTH_TOKEN_NAME, authToken);
}
request.setHeader(USER_AGENT_PROPERTY, AGENT_NAME);
HttpResponse response = client.execute(request);
if ( response.getStatusLine().getStatusCode() == HttpStatus.SC_OK ) {
// read the content
long contentLenght = response.getEntity().getContentLength();
BufferedHttpEntity bufferedHttpEntity = new BufferedHttpEntity(response.getEntity());
Bitmap image = BitmapFactory.decodeStream(bufferedHttpEntity.getContent());
Log.e(TAG, "Bitmap != null " + (image != null) );
return image;
} else {
Log.e(TAG, "HTTP ERROR while executing method: downloadImage: " + response.getStatusLine().getStatusCode());
}
} catch (Exception e) {
Log.e(TAG, "Exception while executing method: downloadImage: " + e.getMessage());
return null;
}
return null;
}