0

I load image within imageview using

 try {
                Bitmap bitmap = BitmapFactory.decodeStream((InputStream)new java.net.URL(SplashItems.get(position).get("imageUrl")).getContent());
                 ImageViewObject.setImageBitmap(bitmap); 

            } catch (MalformedURLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

but it's so so slow, any faster way to do that

Best regards

AMH
  • 6,363
  • 27
  • 84
  • 135

2 Answers2

2

I would recommend using AsyncTask to load. This way your app with still run, and the user can interface while the image loads. I have also found that it cuts the download time by quite a bit because the downloading is done on a background thread and is able to focus on that. Here is a link to help you get started:

http://developer.android.com/reference/android/os/AsyncTask.html

This article also talks about handlers, which may also be of some use to you.

http://www.vogella.com/articles/AndroidPerformance/article.html

Best of luck!

BlackHatSamurai
  • 23,275
  • 22
  • 95
  • 156
1

You can have a look at class ImageDownloader in GoogleTV sample. They use asynctask do download image in background and implement a cache to improve performance. Another tutorial from Android developer blog Multithreading For Performance

And similar question on SO : Loading an image from the Web with Asynctask. The last is UrlImageViewHelper. You can check the performance and choose the best. I myself often use ImageDownloader

Community
  • 1
  • 1
Trung Nguyen
  • 7,442
  • 2
  • 45
  • 87