Search code examples
androidkotlinandroid-asynctaskandroid-glideandroid-background

Android Kotlin - clear glide cache in background thread doesn't work


GlobalScope.launch(Dispatchers.Default) {
    Glide.with(this@UploadProfileImage).clearDiskCache()
}

I get unresolved reference on clearDiskCache

When I do

Glide.with(this).clearDiskCache()

instead then I don't get unresolved reference on clearDiskCache but

None of the following functions can be called with the arguments supplied: 
public open fun with(activity: Activity): RequestManager defined in com.bumptech.glide.Glide
public open fun with(fragment: android.app.Fragment): RequestManager defined in com.bumptech.glide.Glide
public open fun with(context: Context): RequestManager defined in com.bumptech.glide.Glide
public open fun with(view: View): RequestManager defined in com.bumptech.glide.Glide
public open fun with(fragment: androidx.fragment.app.Fragment): RequestManager defined in com.bumptech.glide.Glide
public open fun with(activity: FragmentActivity): RequestManager defined in com.bumptech.glide.Glide

on with


Solution

  • you should use 'Glide.get(context)' instead of 'Glide.with(context)' to use 'clearDiskCache' method.