I have a problem that each time , I take a photo and and I try to display it. Glide load me the old file. I check the file locally , it has been changed successfully. But the old image is displayed.
This is my code :
public void onCameraCaptureCompleted(final File photoFile) {
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
stopCamera();
pickedImg.setImageBitmap(null);
Glide.with(TakePhotoFragment.this)
.load(photoFile)
.asBitmap()
.dontAnimate()
.diskCacheStrategy(DiskCacheStrategy.NONE)
.into(pickedImg);
}
});
}
Who knows how to solve this problem ?
By default, Glide uses memory and disk caching to avoid unnecessary network calls, it checks into multiple layers of caches before initiating a new request call for an image.
Glide is an Image Loader Library for Android developed by bumptech and is a library that is recommended by Google. It has been used in many Google open source projects including Google I/O 2014 official application. It provides animated GIF support and handles image loading/caching.
Glide is faster and the results of Picasso and Coil are similar. But what about when we are loading from the cache. As you can see in the images below we have the best times for Glide in most of the cases.
How Glide Cache Works. By default, Glide checks multiple layers of caches before starting a new request for an image: Active resources — Is this image displayed in another View right now? Memory cache — Was this image recently loaded and still in memory?
Try with skipMemoryCache
Allows the loaded resource to skip the memory cache.
.skipMemoryCache(true)
.diskCacheStrategy(DiskCacheStrategy.NONE)
NOTE
If same problem still coming then use clearMemory()
.
For good approach, Create Application Class and add this
public class RootApplication extends Application
{
@Override public void onLowMemory() {
super.onLowMemory();
Glide.get(this).clearMemory();
}
Make sure, added this Application class in Manifest
.
<application
android:name=".RootApplication"
>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With