bumptech / bumptech/glide

Question: how to cancel a loading task without releasing its resources

Open
#3,118 8 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Java
Stars
35k
Forks
6.2k
Avg merge
1d 11h
Merged PRs (30d)
8

Description

Suppose I have this:

glideTarget = Glide.with(...).asBitmap().load(imageFile)
.apply(RequestOptions.centerCropTransform().skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.NONE))
.into>(object : SimpleTarget(reqWidth, reqHeight) {
override fun onResourceReady(result: Bitmap, transition: Transition?) {
...
}
})

And at some point, maybe during its loading, and maybe afterwards, I wish to request it to cancel the loading . Trying to cancel it when it's already finished shouldn't do anything, and trying to do it while it's still loading will simply avoid calling onResourceReady.

I know I can use this:

Glide.with(this@LiveWallpaperService).clear(glideTarget)

But this releases the resources, so if inside of onResourceReady, I store the bitmap somehow, the next time I reach it, it's actually recycled.

How can I avoid recycling while cancelling loading tasks?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.