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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.