Android - How to record amount of time that accelerometer is over+below a threshold over a long period
In my app I want to count for how long the accelerometer is over a certain threshold, but i'm unsure of how to do this.   
The sensitivity of my accelerometer is set to 'SensorManager.SENSOR_DELAY_GAME' so the onSensorChanged() method is called approximately 20 times a second. I have a flag called movementFlag that I'm setting to true whenever the accelerometer speed goes over a threshold, and setting back to false when it goes under the threshold.    

So say over the space of an hour, I want to count up the total amount of time that the movementFlag is set to true, incrementing this time value each time it's set, and the same for when it's set to false.    
I thought maybe I could have 2 values - moveStart and moveFinish - that I could set to System.currentTimeMillis() upon the transition of movementFlag from true to false and vice versa. Subtracting these values from each other would give me the amount of time the flag is set each time. But I don't know how to do this just on the transition of a flag and not the whole time while a flag is set.  
Can anyone tell me how to do this or another method to do what I want to do here? Thanks
Android - How to record amount of time that accelerometer is over+below a threshold over a long period
===

In my app I want to count for how long the accelerometer is over a certain threshold, but i'm unsure of how to do this.   
The sensitivity of my accelerometer is set to 'SensorManager.SENSOR_DELAY_GAME' so the onSensorChanged() method is called approximately 20 times a second. I have a flag called movementFlag that I'm setting to true whenever the accelerometer speed goes over a threshold, and setting back to false when it goes under the threshold.    

So say over the space of an hour, I want to count up the total amount of time that the movementFlag is set to true, incrementing this time value each time it's set, and the same for when it's set to false.    
I thought maybe I could have 2 values - moveStart and moveFinish - that I could set to System.currentTimeMillis() upon the transition of movementFlag from true to false and vice versa. Subtracting these values from each other would give me the amount of time the flag is set each time. But I don't know how to do this just on the transition of a flag and not the whole time while a flag is set.  
Can anyone tell me how to do this or another method to do what I want to do here? Thanks