Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Glide loads the old image

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 ?

like image 525
Imene Noomene Avatar asked Nov 24 '17 15:11

Imene Noomene


People also ask

Does glide cache images by default?

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.

What is Glide 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.

Is glide better than Picasso?

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 do you cache images on Glide?

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?


1 Answers

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"
 >
like image 151
IntelliJ Amiya Avatar answered Oct 10 '22 18:10

IntelliJ Amiya