Clear Glide Image Cache in Android

独自空忆成欢 提交于 2019-12-06 09:30:18

问题


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:


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.



来源:https://stackoverflow.com/questions/36168383/clear-glide-image-cache-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!