ImageLoader - do not load an image if it is already cached.

I don't want to load images if they are already cached. I am using the ImageLoader library from NOSTRA. Please tell me if there is a way to do this. Below is the code: -

    DisplayImageOptions options = new DisplayImageOptions.Builder()
                        .showStubImage(R.drawable.ic_stub)
                        .showImageForEmptyUri(R.drawable.ic_sample)
                        .resetViewBeforeLoading()
                        .cacheInMemory()
                        .cacheOnDisc()
                        .imageScaleType(ImageScaleType.EXACTLY_STRETCHED)
                        .bitmapConfig(Bitmap.Config.ARGB_8888)
                        .build();
                imageLoader.displayImage(url2.toString()
                                          ,thumbnail,options, new                                 
                    ImageLoadingListener() {
                    @Override
                    public void onLoadingStarted() {

                       // progressBar.setVisibility(grid.VISIBLE);
                        //  grid.notify();
                    }

                    @Override
                    public void onLoadingFailed(FailReason failReason) {

                       //progressBar.setVisibility(grid.GONE);
                        //  grid.notify();

                    }

                    @Override
                    public void onLoadingComplete(Bitmap bitmap) {


                      //  progressBar.setVisibility(grid.GONE);
                        // grid.notify();
                    }

                    @Override
                    public void onLoadingCancelled() {

                       //  progressBar.setVisibility(grid.GONE);
                        //grid.notify();

                    }
                });

      

+3


source to share


1 answer


You haven't defined default caching options in DisplayImageOption

.

ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(this)
    .threadPoolSize(5)
    .threadPriority(Thread.MIN_PRIORITY + 3)
    .denyCacheImageMultipleSizesInMemory()
    // 1MB=1048576 
    .memoryCacheSize(1048576 * 5)
    .discCache(new UnlimitedDiscCache(cacheDir))
    .build();

      

Here cacheDir

is the directory that can be on SD card

(requires "android.permission.WRITE_EXTERNAL_STORAGE" permission) or application cache

.

I have provided cacheDirectory

in my application.



File cacheDir = new File(this.getCacheDir(), "name of directory");
    if (!cacheDir.exists())
        cacheDir.mkdir();

      

Now provide config ImageLoader

by executing code before loading any image,

imageLoader.init(config);

      

+6


source







All Articles