Rotation and Object Continuity
Now you are a good citizen, which is nice. Unfortunately, your app no longer handles rotation correctly. Try playing the 69_ohm-loko sound and rotating the screen: The sound will stop abruptly. (If it does not, make sure you have built and run the app with your recent onDestroy() implementation.)
Here is the problem: On rotation, the BeatBoxActivity is destroyed. As this happens, the FragmentManager destroys your BeatBoxFragment, too. In doing that, it calls BeatBoxFragment’s waning lifecycle methods: onPause(), onStop(), and onDestroy(). In BeatBoxFragment.onDestroy(), you call BeatBox.release(), which releases the SoundPool and stops sound playback.
You have seen how Activity and Fragment instances ...
Get Android Programming: The Big Nerd Ranch Guide, Third 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.