Search code examples
androiduniversal-image-loader

Image not displaying sometimes with Universal Image Loader


I have an activity that contains an ImageView, I call this activity every time I want to open an image for better viewing. The problem is that sometimes my ImageLoader works fine but sometimes it does not display the image. I use universal-image-loader-1.8.4.jar and android 4.2.2

When my ImageLoader not display my image I get in the log:

ImageView is reused for another image. Task is cancelled.

My configuration:

ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(this)
.enableLogging()
.threadPriority(Thread.MAX_PRIORITY)
.build();       
imageLoader.init(config);

My method:

private void getImage() {
 Bundle bundle = getIntent().getExtras();
 String dir= bundle.getString("poster");
 imageLoader.displayImage(dir, imgPoster);
}

Can anyone help me?


Solution

  • I meet the problem too, this is because you want to set the adapter or show the image before the activity was created.

    Try this:

    String dir = "";
    
    Handler mHandler = new Handler(){
            public void handleMessage(android.os.Message msg) {
                switch(msg.what){
                    case 0:
                        imageLoader.displayImage(dir, imgPoster);
                        break;
                }
            };
        };
    
    private void getImage() {
           Bundle bundle = getIntent().getExtras();
           dir= bundle.getString("poster");
           mHandler.sendEmptyMessageDelayed(0,500);
    }