Class CannonGameFragment
’s onPause
and onDestroy
methods (Section 6.7) call class CannonView
’s stopGame
and releaseResources
methods (Fig. 6.17), respectively. Method stopGame
(lines 464–468) is called from the main Activity
to stop the game when the Activity
’s onPause
method is called—for simplicity, we don’t store the game’s state in this example. Method releaseResources
(lines 471–475) calls the SoundPool
’s release method to release the resources associated with the SoundPool
.
463 // stops the game; called by CannonGameFragment's onPause method
464 public void stopGame()
465 {
466 if (cannonThread != null)
467 cannonThread.setRunning(false); // tell thread to terminate
468 }
469
470 // releases resources; called by CannonGame's onDestroy method
471 public void releaseResources()
472 {
473 soundPool.release(); // release all resources used by the SoundPool
474 soundPool = null;
475 }
476