如何加速RSS Parser解析feed和缩略图

时间:2022-06-01 01:42:45

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.

我为我的播客应用编写了一个rss解析器。如果我使用不同的播客解析rss feed并在ListView中显示结果,我的解析器需要大约1-2秒才能解析整个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.

但是,如果我想在ListView中包含每个播客的缩略图,我需要先下载缩略图并使用BitmapFactory创建一个Bitmap,然后我可以将Bitmap存储到ImageView中。

Unfortunately this stretches my execution time from 1-2 seconds up to 8-10 seconds.

不幸的是,这将我的执行时间从1-2秒延长到8-10秒。

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);
                currentItem.setBitmap(BitmapFactory.decodeByteArray(bb, 0, bb.length));
            }
     }
}

1 个解决方案

#1


1  

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

您应该使用单独的线程来下载位图。这称为延迟加载。请参阅我的教程: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

或者这个问题的答案:在ListView中延迟加载图像

#1


1  

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

您应该使用单独的线程来下载位图。这称为延迟加载。请参阅我的教程: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

或者这个问题的答案:在ListView中延迟加载图像