Methods onPause and disableAccelerometerListening

To ensure that accelerometer listening is disabled when the DoodleFragment is not on the screen, we override Fragment lifecycle method onPause (Fig. 7.15, lines 75–80), which calls method disableAccelerometerListening (lines 83–93). Method disableAccelerometerListening uses class SensorManager’s unregisterListener method to stop listening for accelerometer events.

74      // stop listening for sensor events75      @Override76      public void onPause()77      {78         super.onPause();79         disableAccelerometerListening(); // stop listening for shake80      }81 82      // disable listening for accelerometer events83      public void disableAccelerometerListening() ...

Get Android™ How to Program, Second Edition now with O’Reilly online learning.

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