Android Programming: The Big Nerd Ranch Guide, 4th Edition
by Bill Phillips, Chris Stewart, Kristin Marsicano, Brian Gardner
Challenge: Preloading and Caching
Users accept that not everything can be instantaneous. (Well, most users.) Even so, programmers strive for perfection.
To approach instantaneity, most real-world apps augment the code you have here in two ways: adding a caching layer and preloading images.
A cache is a place to stash a certain number of Bitmap objects so that they stick around even when you are done using them. A cache can only hold so many items, so you need a strategy to decide what to keep when your cache runs out of room. Many caches use a strategy called LRU, or “least recently used.” When you are out of room, the cache gets rid of the least recently used item.
The Android support library has a class called LruCache
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access