For the More Curious: Canceling Requests

In your current implementation, PhotoGalleryFragment asks its ViewModel, PhotoGalleryViewModel, to start a web request to download photo data. If the user presses the Back button quickly enough after launching your application, it is possible that the web request will continue even after the user exits the activity. This will not cause a memory leak, because FlickrFetchr does not hold references to any UI-related components, nor to the ViewModel.

However, since you are ignoring the results, allowing the request to continue will cause some minimal wasted battery, wasted CPU cycles, and possibly some wasted paid data usage if the user is on a metered network. Granted, there is no major harm in ...

Get Android Programming: The Big Nerd Ranch Guide, 4th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.