Steps during activity

Has someone implemented something like "steps during activity"?

I tried to do something like this on data field:

[FONT=monospace, monospace]var aActivityMonitorInfo = ActivityMonitor.getInfo[];[/FONT]
[FONT=monospace, monospace]if [aActivityMonitorInfo has :steps && aActivityMonitorInfo.steps != null][/FONT]

[FONT=monospace, monospace]{[/FONT]
[FONT=monospace, monospace]if [m_ElapsedTime < 1][/FONT]
[FONT=monospace, monospace] {[/FONT]
[FONT=monospace, monospace] m_StepsBeforeActivity = aActivityMonitorInfo.steps;[/FONT]
[FONT=monospace, monospace] }[/FONT]
[FONT=monospace, monospace]else[/FONT]
[FONT=monospace, monospace] {[/FONT]
[FONT=monospace, monospace] m_StepsDuringActivity = aActivityMonitorInfo.steps - m_StepsBeforeActivity[/FONT][FONT=monospace, monospace];[/FONT]
[FONT=monospace, monospace] }[/FONT]
[FONT=monospace, monospace]}[/FONT]

It seemed to work well on the sim, but when I tested on a real VAHR it counted too many steps.
  • I do steps in a few apps, but make sure it's only counting when the activity isn't paused. Also, it gets a bit trickier if you are running the app over midnight, when daily steps get reset.

    I'll see how one of my apps does on the va-hr and post if I see anything odd.
  • the code how only to count the activity steps is part of my first tutorial, see here: http://starttorun.info/tutorial-1-create-a-connect-iq-datafield/

    Peter.
    My apps in the store
    &#8203;&#8203;&#8203;&#8203;&#8203;&#8203;&#8203;
  • Thanks for the answers, guys.

    I just tested my program on my VAHR and now it looked ok. Something must have gone wrong in my first tests.

    Indeed my implementation would count the steps even when the activity is paused and I completely overlooked the fact that someone may run the app overnight. Anyway, I don't think I will write code to work around these issues, as I'm really trying to save memory. This is why I use elapsedTime < 1 to check if the activity was started, for instance.

    Peter's implementation is certainly a lot more elegant and suitable for a tutorial. I'd be pleased to check your implementation too, Jim.





  • To handle the overnight situation is relatively easy, you can either check the System.getClockTime or in this case (my preferred option would be to) just check when the ActivityMonitor.steps decrease and when that happens you offload what you have recorded so far to another var (eg StepsOfPastDays). When displaying you add the StepsOfPastDays to your total.

    Peter.
    My apps in the store