1

I have several images on some of my Activities, and these are all connected from Remote Server. The problem is every time I go on one of these Activities that contain images from remote sever. All of the images must load first otherwise you will get a black empty screen. Sometimes it takes about 1-5 minutes to load, and sometimes it even force close the device. Is there anyway I can fix this issue?

Here is the code I'm using:

ImageViewimgView =(ImageView)findViewById(R.id.image01);
        Drawable drawable = LoadImageFromWebOperations("http://forum.roda.hr/images/customavatars/avatar10164_2.gif");
        imgView.setBackgroundDrawable(drawable);



private Drawable LoadImageFromWebOperations(String url) {
        try {
            InputStream is = (InputStream) new URL(url).getContent();
            Drawable d = Drawable.createFromStream(is, "src name");
            return d;
            }
        catch (Exception e) {
            System.out.println("Exc="+e);
            return null;
        }
    }

I have been struggling for days trying to figure this out, please help me, it would be really mean a lot to me. Thanks in advance!

pankajagarwal
  • 13,462
  • 14
  • 54
  • 65
Kuwame Brown
  • 533
  • 1
  • 10
  • 22

3 Answers3

1

http://www.androidpeople.com/android-load-image-url-example

this should help..

and as jett try doing it in lazy with AsynTask to do the loading in background..

Jana
  • 2,890
  • 5
  • 35
  • 45
0

The key point is that you should use Thread to load the images from Internet.
Please refer to Android - How do I do a lazy load of images in ListView to achieve this.

Community
  • 1
  • 1
Jett Hsieh
  • 3,159
  • 27
  • 33
0

Better to use thread to download image.
Refer this
Load Image from server using thread
Painless Threading

Labeeb Panampullan
  • 34,521
  • 28
  • 94
  • 112