Hi, I'm working on an app that takes advantage of the accelerometer. I use the SensorEventListener library to do this. However, I have had a problem where I believe the accelerometer did not shut off with my application. I discovered this because after I was working on/debugging my application for a while, I went to the store, and my phone's battery was drained quite a bit by the time I got home. I looked at what was draining my battery, and it was my application, even though I wasn't even running it (it didn't show up in the task manager).
I override the function "onStop()" with the following code:
Will this always turn off the accelerometer when my app exits? Was that one occurrence just a freak accident or should I do something else to ensure that the accelerometer is turned off?
Thanks in advance.
I override the function "onStop()" with the following code:
Code:
super.onStop();
sensorManager.unregisterListener(this, sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER));
sensorManager.unregisterListener(this, sensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION));
Will this always turn off the accelerometer when my app exits? Was that one occurrence just a freak accident or should I do something else to ensure that the accelerometer is turned off?
Thanks in advance.