Methods onStart and enableAccelerometerListening
Accelerometer listening should be enabled only when the DoodleFragment
is on the screen. For this reason, we override Fragment
lifecycle method onStart (Fig. 7.14, lines 53–58), which calls method enableAccelerometerListening
(lines 61–72) to begin listening for accelerometer events. A SensorManager
is used to register listeners for accelerometer events.
52 // start listening for sensor events53 @Override54 public void onStart()55 {56 super.onStart();57 enableAccelerometerListening(); // listen for shake58 }59 60 // enable listening for accelerometer events61 public void enableAccelerometerListening()62 {63
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.