Android Programming: The Big Nerd Ranch Guide, 4th Edition
by Bill Phillips, Chris Stewart, Kristin Marsicano, Brian Gardner
Challenge: Improving ThumbnailDownloader’s Lifecycle Awareness
LiveData is a lifecycle-aware component that removes itself as an observer automatically based on events from its lifecycle owner.
Update ThumbnailDownloader so that it will remove itself as an observer automatically when the lifecycle it observes emits an ON_DESTROY event.
To do this, ThumbnailDownloader will need a reference to each of the lifecycles it observes.
The fact that ThumbnailDownloader observes both the fragment lifecycle and the fragment view lifecycle tightly couples ThumbnailDownloader to Fragment. There are many different ways to clean this up, but here we ask you to take one small step: Refactor ThumbnailDownloader so that it only observes the fragment ...
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