For the More Curious: Detecting the Visibility of Your Fragment

When you reflect on your PhotoGallery implementation, you may notice that you used the global broadcast mechanism to broadcast the SHOW_NOTIFICATION intent. However, you locked the receiving of that broadcast to items local to your app process by using custom permissions. You may find yourself asking, “Why am I using a global mechanism if I am just communicating with things in my own app? Why not a local mechanism instead?”

This is because you were specifically trying to solve the problem of knowing whether PhotoGalleryFragment was visible. The combination of ordered broadcasts, standalone receivers, and dynamically registered receivers you implemented gets the job done. ...

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.