Skip to content
Advertisement

How to priorly get future Glide image size which will be stored in cache in Android/Java?

In MainActivity, I’m loading some images using glide into recyclerview according to imageview size.

See:

JavaScript

XML:

JavaScript

As you can observe, I’m using Glide cache DiskCacheStrategy.AUTOMATIC also so that next time without Internet Glide can show the images. Now you can read in this post https://medium.com/@multidots/glide-vs-picasso-930eed42b81d that ” Glide resizes the image as per the dimension of the ImageView.

Now, I want that final size inside SpalshActivity, which Glide will be stored in cache. So that when After SpalshActivity, when user opens MainActivity without Internet Conncetion for the very first time also, then it should load Images.

So how is it possible?

In SpalshActivity, I’m already caching Images, but it is again downloading/resizing in MainActivity for the very first time.

SpalshActivity:

JavaScript

Advertisement

Answer

Better to preload all the images with .downloadOnly() instead of using any target. Then load images using FileProvider.

JavaScript

And store the path alongside URL in SQLite. Now get the image_url using FileProvider from SQLite

JavaScript

You may also need to add,

In manifest, inside <application>

JavaScript

Inside res/xml, as file_paths.xml,

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement