1

I'm making an Android application and part of the application calls a Google API for photos for specific locations. These photos will be part of a list and I want to make it so once I call the API and download the photo, I can save it locally and resuse that later rather than recall the API. My code is pasted below

fun placePhotoCall(ref : String, view : ImageView, index : Int) {
    if(places[index].image == null) {
        Glide.with(this).load(createPhotosRequestURL(ref)).into(view)
        places[index].image = view.image
    }
    else {
        view.setImageDrawable(places[index].image)
    }
}

This function calls the API, downloads the photo, and stores it in the ImageView. I want to take the drawable image out of said ImageView and store it in an object I created however no matter what I try the image property remains null.

Thanks in advance.

Jacob
  • 299
  • 1
  • 18
Daniel N.
  • 357
  • 2
  • 20
  • https://stackoverflow.com/questions/27394016/how-does-one-use-glide-to-download-an-image-into-a-bitmap this thread shows how you could accomplish what you're describing... but if you're looking for a simple caching mechanism, Glide / Picasso will do that for you behind the scenes. – em_ Jun 26 '18 at 18:09

1 Answers1

2

Don't store an array of the drawables, it's too much data to try to do it that way. Just store an array of the ref Strings you're using to load that image and reload the image using the ref string anywhere you need to. The Glide package already caches images so you just pass it your ref String and it only downloads the image again if necessary.

CodeSmith
  • 1,621
  • 1
  • 13
  • 31