1

I'm trying to implement Image Caching into my app. The code i currently have regarding the images is below:

Network call to get images:

public void getImage(String url, final ImageView imageView) {

    System.out.println("Image Url is: " + url);
    ImageRequest requestImage = new ImageRequest(url, new Response.Listener<Bitmap>() {
        @Override
        public void onResponse(Bitmap response) {
            imageView.setImageBitmap(response);
        }
    }, 0, 0, null, null);

    queue.add(requestImage);
}

How could I implement the caching? I have read a few articles on SO, but am not sure on how to implement it into my app?

Thanks for your help

Stillie
  • 2,647
  • 6
  • 28
  • 50

2 Answers2

2
  1. You have better use ImageLoader instead of using ImageRequest directly.
  2. When you instantiate an ImageLoader object, you set an ImageCache object. (That is what you want, isn't it?)

Volley's ImageLoader uses internally ImageRequest convined with ImageCache.

hata
  • 11,633
  • 6
  • 46
  • 69
  • how to add the image loader in the request ? if i have the below mNetworkImageView = (NetworkImageView) findViewById(R.id.ImageView); mImageLoader = MySingleton.getInstance(this).getImageLoader(); mNetworkImageView.setImageUrl(IMAGE_URL, mImageLoader); .. it works without a request , do I need a request to cash it ? – Moudiz Aug 13 '15 at 06:08
0

I think you should try this one of the best image caching library :

https://github.com/loopj/android-smart-image-view

Jai
  • 1,974
  • 2
  • 22
  • 42