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 O’Reilly online learning.

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