How to speed up RSS Parser parsing feed and thumbnails
I wrote a rss parser for my podcast app. If I am parsing a rss feed with different podcasts and showing the result in a ListView
, it takes about 1-2 seconds for my parser to parse the whole feed.
However, if I want to include a thumbnail of each podcast in my ListView
, I need to download the thumbnail first and create a Bitmap with BitmapFactory
and then I can store the Bitmap into an ImageView
.
Unfortunately this stretches my execution time from 1-2 seconds up to 8-10 seconds.
This is how I grab the thumbnail. Is there a better (and faster) method to achieve what I want to do and if there is one, how can I achieve it?
Thanks in advance.
...
else if (name.equalsIgnoreCase(THUMBNAIL)) {
HttpGet get = new HttpGet(parser.nextText());
if (get != null && get.getURI().toString().length()>1) {
HttpClient client = new DefaultHttpClient();
HttpResponse response = client.execute(get);
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
HttpEntity entity = response.getEntity();
if (entity != null) {
byte[] bb = EntityUtils.toByteArray(entity);
开发者_JAVA技巧 currentItem.setBitmap(BitmapFactory.decodeByteArray(bb, 0, bb.length));
}
}
}
You should use a separate thread to download the bitmaps. This is called lazy loading. See my tutorial: http://negativeprobability.blogspot.com/2011/08/lazy-loading-of-images-in-listview.html
or the answers to this question: Lazy load of images in ListView
精彩评论