diff --git a/core/java/android/hardware/SensorManager.java b/core/java/android/hardware/SensorManager.java index 97921feea79a5..006872436e475 100644 --- a/core/java/android/hardware/SensorManager.java +++ b/core/java/android/hardware/SensorManager.java @@ -34,11 +34,19 @@ import java.util.HashMap; import java.util.List; /** + *

* SensorManager lets you access the device's {@link android.hardware.Sensor * sensors}. Get an instance of this class by calling * {@link android.content.Context#getSystemService(java.lang.String) * Context.getSystemService()} with the argument * {@link android.content.Context#SENSOR_SERVICE}. + *

+ *

+ * Always make sure to disable sensors you don't need, especially when your + * activity is paused. Failing to do so can drain the battery in just a few + * hours. Note that the system will not disable sensors automatically when + * the screen turns off. + *

* *
  * public class SensorActivity extends Activity, implements SensorEventListener {
@@ -48,13 +56,22 @@ import java.util.List;
  *     public SensorActivity() {
  *         mSensorManager = (SensorManager)getSystemService(SENSOR_SERVICE);
  *         mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
+ *     }
+ *
+ *     protected void onResume() {
+ *         super.onResume();
  *         mSensorManager.registerListener(this, mAccelerometer, SensorManager.SENSOR_DELAY_NORMAL);
  *     }
  *
+ *     protected void onPause() {
+ *         super.onPause();
+ *         mSensorManager.unregisterListener(this);
+ *     }
+ *
  *     public void onAccuracyChanged(Sensor sensor, int accuracy) {
  *     }
  *
- *     public abstract void onSensorChanged(SensorEvent event) {
+ *     public void onSensorChanged(SensorEvent event) {
  *     }
  * }
  *