Glide loads the old image

Viewed 1689

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 ?

3 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"
 >

you may want to clear the cache stored and then restart the application manually

or

just clear the cache from code only. just call clearMemory() on glide.

Have a look here for more info

Docs

.skipMemoryCache(true)
.diskCacheStrategy(DiskCacheStrategy.NONE)

just this worked for me.

Related