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? Some people suggest me to use Thread, but I really don't know how make one. Can some give me someone example, I would really appreciate a lot.

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;
        }
    }
Nimantha
  • 6,405
  • 6
  • 28
  • 69
Kuwame Brown
  • 533
  • 1
  • 10
  • 22

2 Answers2

0

Try this example, which uses AsyncTask and ProgressDialog to perform work in background and to show user that work is in progress.

Vladimir Ivanov
  • 42,730
  • 18
  • 77
  • 103
0

I recommend the DroidFu library for this. It has a WebImageView widget, which will handle the loading of images from a remote source. https://github.com/kaeppler/droid-fu

Zsombor Erdődy-Nagy
  • 16,864
  • 16
  • 76
  • 101