bumptech / bumptech/glide

How to use memory caching when loading Drawable resources?

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

Description

My current requirement is to display the icons of installed applications in a list and convert them into rounded corners.

` public static Drawable getAppIcon(final String packageName) {
if (UtilsBridge.isSpace(packageName)) return null;
try {
PackageManager pm = Utils.getApp().getPackageManager();
PackageInfo pi = pm.getPackageInfo(packageName, 0);
return pi == null ? null : pi.applicationInfo.loadIcon(pm);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
return null;
}
}`
Currently, I use this method to get the icon Drawable for each item in the list and then use Glide's load(Drawable) method. However, there is a problem because the EngineKey compares Drawable objects using reference equality, and my Drawable objects are always new instances, so they cannot hit the cache. I tried using requestBuilder.signature(new ObjectKey(pkgName)), but it doesn't work because the model objects are not equal, and the ObjectKey has no effect.

How can I make Drawable objects hit the memory cache?
Do I need to store Drawable objects for each application package name myself? Will this increase memory usage? And when should I release them?

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.