I'm trying to preload list of images in one activity then start another activity and load these images into imageviews that are already preloaded in cache.
I have two questions If I preload images in one activity, will they be available for load in another activity? Am I doing the method with glide correctly or am I missing something? Are there other more good practice ways to preload images?
I have tried Glide
to preload images, but the images still take a long time to load in the another activity
Glide.with(requireContext())
.load(imageStory.image)
.diskCacheStrategy(DiskCacheStrategy.RESOURCE)
.preload();
Then loading them into imageview in another activity
Glide.with(this)
.load(stories[counter].image)
.diskCacheStrategy(DiskCacheStrategy.RESOURCE)
.into(binding.storyDisplayImage)
I expect that the list of images that I have preloaded in one activity will load many times faster in another activity than if I had not preloaded them
If someone searching for the same, there is the answer that I found
I found a workaround using another library, that is coil. For me, it seemed much simpler and a little better in all areas compared to glide.
fun preloading(uri: Uri?) { //for preloading images in cache
val request = ImageRequest.Builder(requireContext())
.data(uri)
.build()
requireContext().imageLoader.enqueue(request)
}
And to load images in other activities or fragments
binding.storyDisplayImage.load(stories[counter].image)