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 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.