Bitmap Cache
suggest changeVersions
LruCache, used below for bitmap caches, has been available since Android 4.0 (API 12).
Introduction
Cache bitmaps so you can reuse objects that are expensive to create. This matters for animation: a garbage-collection pause stops the animation and the app looks sluggish. Loading a bitmap into memory is itself a cache of that bitmap. Bitmap memory on Android is easy to get wrong, so cache a bitmap you will draw more than once.
Syntax
LruCache<String, Bitmap> mMemoryCache;declares the cache.void addBitmapToMemoryCache(String key, Bitmap bitmap)adds a bitmap.Bitmap getBitmapFromMemCache(String key)returns a cached bitmap.
Parameters
| Parameter | Details |
|---|---|
| key | Key used to store the bitmap in the memory cache. |
| bitmap | Bitmap stored for that key. |
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents