-3

I want to download multiple images from URL and then save them into internal cache. Every time when i come back to my app then if the image is already downloaded then it will be fetched from cache otherwise download it. Please provide a working solution for this.

Arpit Jain
  • 1
  • 1
  • 4
  • Use shared preference , when download process is completed then save url into a key using shared preference, when next time come to app check this key , if is not empty show images with his value else download process start. – Avinash Feb 10 '20 at 04:27
  • 2
    i think your question is similar to [this](https://stackoverflow.com/questions/32941372/load-image-from-url-to-imageview-as-well-as-cache) – Chheangly Prum Feb 10 '20 at 04:29
  • 1
    have you tried anything from your side? if yes, then you can post the details of it and then explain what is not working in your code – AADProgramming Feb 10 '20 at 04:42
  • Yes i have used LRU cache for that but it works only if my app is in background.If app is closed from background then it will redownload all the images. Have a look at this link: https://stackoverflow.com/questions/1945201/android-image-caching/23487962#23487962 – Arpit Jain Feb 10 '20 at 04:56

1 Answers1

1

I have one suggestion for you

use Glide Library it has inbuilt functionality to store the loaded images in the cache as per your needed and then it will reload from cache automatically.

Glide : https://github.com/bumptech/glide

usage:

Glide.with(context)
.load("image-url")
.diskCacheStrategy(DiskCacheStrategy.DATA)
.into(imageView);

use diskCacheStrategy to store images in cache, memory, resources wherever you want.

Solanki Zeel
  • 548
  • 1
  • 7
  • 18