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 lifecycle. Then have the fragment clear the queue when Fragment.onDestroyView() is called. This way, your downloader could more easily be used with an activity, too.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.81.72.247