Clear Glide Image Cache in Android

2020-07-21 05:22发布

I am using glide library for showing images. I am trying to clear glide cache by using the following code:

Glide.get(MainActivity.this).clearDiskCache();
Glide.get(MainActivity.this).clearMemory();

the above code is inside Async and I call in Do background part.

When I run this I am always getting:

Caused by: java.lang.IllegalArgumentException: You must call this method on the main thread
at com.bumptech.glide.util.Util.assertMainThread(Util.java:135)
at com.bumptech.glide.Glide.clearMemory(Glide.java:370)

What could be wrong here? If I use the above in MainThread it is asking to run it in background.

How do I clear cache?

Thanks!

1条回答
虎瘦雄心在
2楼-- · 2020-07-21 05:47

clearMemory() must be called on the main thread. clearDiskCache() must be called on a background thread.

You can't call both at once on the same thread.

查看更多
登录 后发表回答