在Android中清除Glide图像缓存

San*_*air 2 java android android-glide

我正在使用滑动库来显示图像.我试图通过使用以下代码清除滑动缓存:

Glide.get(MainActivity.this).clearDiskCache();
Glide.get(MainActivity.this).clearMemory();
Run Code Online (Sandbox Code Playgroud)

上面的代码在Async中,我在Do背景部分调用.

当我运行这个时,我总是得到:

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)
Run Code Online (Sandbox Code Playgroud)

这可能有什么问题?如果我在MainThread中使用上面的内容,则要求在后台运行它.

如何清除缓存?

谢谢!

Sam*_*udd 8

clearMemory()必须在主线程上调用. clearDiskCache()必须在后台线程上调用.

你不能在同一个线程上同时调用它们.