The feed is the product for a large share of consumer apps, and the feed is a list with no end. The assumption in most planning meetings is that the framework handles the memory. That assumption is half right, and the wrong half is the expensive one.
What the Library Gives You
Android's paging library loads a list one page at a time, and its documentation lists the benefits plainly: "In-memory caching for your paged data" and "Built-in support for error handling, including refresh and retry capabilities" (Android). Those are real, and rebuilding them by hand is rarely a good use of a team.
What It Does Not Do Unless Asked
Our own article said the library discards pages the user has scrolled past. By default it does not. The setting that would bound memory defaults to unlimited, and the reference spells out the consequence: "the maximum number of items loaded is unbounded, and pages will never be dropped" (Android). A customer who scrolls ten thousand items is holding ten thousand items, on a phone that may be four years old.
One configuration value fixes it. Somebody has to know to set it.
The Bug in the Example Everyone Copies
The second correction was in sample code. The first request for a list deliberately asks for more than one page, and code that passes that larger size to a page-numbered service fetches the second page twice. Customers see duplicated rows. It passes review because it looks exactly like the pattern in many tutorials, including the one we published.
The Database Is the Screen
For a list that must work offline, the documented design is strict: "the app uses the database as the source of truth" (Android). The network fills the database and the screen reads only from it. Teams that let the network write to the screen directly get a list that behaves differently online and offline.
What to Ask Your Team
- Is there an upper bound on how much of a list we keep in memory?
- Have we tested a long scroll on our oldest supported phone?
- Does the list show the same data with the network off?
- Has anyone checked the feed for duplicate rows after the first page?
-Rocky
#MobilePerformance #Android #ProductQuality #EngineeringDreams #StrategiaX
Originally published on ANDROID-ARCHITECT, the Android engineering blog of Strategia-X, with the corrected code.
