2

I have been using this algorithm - (how to calculate exact foot step count using accelerometer in android?) to calculate the number of steps taken. I unregister the sensor manager listener in the onPause() method of my activity.

mSensorManager.unregisterListener(this);

When the phone's screen is off, my steps aren't counted. How do I count the steps using the accelerometer even when the phone's screen is switched off? Please guide me.

Community
  • 1
  • 1
Dhruv
  • 117
  • 9

1 Answers1

2

You should read about the activity lifecycle first. The onPause method is called when the screen turns off, so you are not listening when the screen is off. You could instead use a background service to listen continuously to the accelerometer sensor.

Hielko
  • 243
  • 1
  • 10