Step counter do not reset the number of steps

I can start and stop the recording steps with Sensor.TYPE_STEP_COUNTER, by registering and canceling the listening.

However, the actual value that is passed to my application through the object SensorEventdoes not reset to zero when the application is destroyed. If I close the application and restart it, or even if I recompile my application with updates, the counter will close where it left off.

If I run other applications that use the step counter sensor, they will independently count their steps and reset their counter.

Does the sensor have an application specific cache? What is the correct way to reset the sensor to zero?

+4
source share
2 answers

From the Android Sensor API :

public static final int TYPE_STEP_COUNTER

This type of sensor returns the number of steps the user has taken since the last reboot upon activation . The value is returned as a float (with the fractional part set to zero) and reset to zero only when the system reboots .

(Emphasis mine)

As you can see, while the sensor is activated, the value will increase without resetting to zero until the system reboots.

If you want to count from 0 every time the application is launched, you can save the first value returned as the initial value, and then subtract the subsequent value.

+16
source

Sensor onSensorChanged , , , , .

SharedPreferences, , onSensorChanged, , 1, , sensorChanged ,

+2

Source: https://habr.com/ru/post/1533442/


All Articles