Whenever I sign in to my app. The image gets loaded slowly. It usually takes lot of time to load.
I'm using Glide
as a library for the Image loading in my app.
Glide.with(photoImageView.getContext())
.load(message.getPhotoUrl())
.into(photoImageView);
This above code is used for loading the image to the ImageView
on my UI as you can see the full image takes lot of time to load.
What could be done in order to load the images faster from Firebase
storage ?
Consider revising the disk cache type.
.skipMemoryCache( false ) to specifically tell Glide to not skip the memory cache thus faster loading.Also,you can change Glide's behavior of disk caching with the .diskCacheStrategy() method.
DiskCacheStrategy.NONE caches nothing
DiskCacheStrategy.SOURCE caches only the original full-resolution
image. In our example above that would be the 1000x1000 pixel one
DiskCacheStrategy.RESULT caches only the final image, after reducing
the resolution (and possibly transformations) (default behavior)
DiskCacheStrategy.ALL caches all versions of the image
Instead of loading from url, you can also try using inbuilt FIREBASE Image loader
StorageReference storageReference = //make a Reference to your Image
Glide.with(context)
.using(new FirebaseImageLoader())
.load(storageReference)
.into(ImageView);
You can preload images when your app starts with Glide.preload() or use built in Glide cache
With the help of Krish (on StackOverflow). He suggested me to change this code
Glide.with(photoImageView.getContext())
.load(message.getPhotoUrl())
.into(photoImageView);
to this code. It is working flawlessly with the below code.
Glide.with(getContext())
.load(message.getPhotoUrl())
.asBitmap()
.centerCrop()
.into(new SimpleTarget < Bitmap > () {
@Override
public void onResourceReady(Bitmap resource, GlideAnimation << ? super Bitmap > glideAnimation) {
photoImageView.setImageBitmap(resource);
}
});
You May also Consider Using Picasso, IMHO it loads faster than Glide.