Does system call compute in background

-wf

-activity

-start - my df ciq

-back to wf

question: does system call compute functione in df when df is not in foreground?

  • I'm going to guess that the answer is yes, otherwise it seems that a lot of data fields would be broken when you go to the watchface during an activity -- i.e. any data fields that calculate an activity average or lap average. I've never noticed this problem with my data field apps, nor have I gotten any complaints.

    https://developer.garmin.com/connect-iq/api-docs/Toybox/WatchUi/DataField.html#compute-instance_function

    This method is called once per second

    You could probably answer this question yourself by creating a test app that:

    - Adds one to a counter (initialized at 0) every time compute() is called, as long as the timer is running. See ActivityInfo.timerState: [https://developer.garmin.com/connect-iq/api-docs/Toybox/Activity/Info.html#timerState-var]

    - Displays the counter (optionally formatted as minutes and seconds)

    You could put your data field on the same page as the native Timer field, and start the activity. The two values should be in sync (or close enough), since compute is supposed to be called roughly once per second.

    Now switch to the watchface for a significant period of time (like 10-30 seconds), then go back to your activity. The values will either still be in sync, or your datafield should be 10-30 seconds behind the native Timer. Either way you'll have your answer.

  • of course I can make test and you don't to have to write how to do it Slight smile

    but first, maybe there is no something in doc and someone met this problem

    I ask because from time to time my df doesn't count proper average of data, I collect data in compute. I have to check it deeply.

  • but first, maybe there is no something in doc and someone met this problem

    I ask because from time to time my df doesn't count proper average of data, I collect data in compute. I have to check it deeply.

    Interesting. I haven't noticed that, but I haven't looked too closely recently. I would consider that a bug, for what it's worth.

  • but first, maybe there is no something in doc and someone met this problem

    Yeah but my point was I haven't seen the problem, so I suggested a simple way to test it and also gave my reasoning for why the answer is probably "yes". Otherwise, lots of data fields would be broken whenever you switch to the watchface during an activity.

    Considering that nobody else has answered, that's the best I can do, except for this:

    I was able to test this using my data field AppBuilder 5, which allows you to specify a data formula in user settings (kind of like excel for Garmin watches Rolling eyes)

    I used the formula SUM(1) which just adds one to the current value (initialized at 0), once per second, as long as the timer is running. I also used a display format of Time, which converts the value (assumed to be in seconds) to [hh]:mm:ss, like the native Timer field.

    I put my data field next to the native Timer and I found it to lag around 1/2 to 1 second behind the native field (which matches what I've seen in the past.)

    While the timer was still running, I switched to the watchface for 30 seconds. When I returned to the activity, the timer was still running and my data field was still in sync with the native field.

    I have a 935.

    If you can get different results on your watch, I'd call that a bug. Obviously my test is very simple since I'm not collecting data in compute(), just adding one to a variable. Maybe in your case, compute() is being called with stale data? I have no idea tbh.

    Obviously another way to test this would be to record FIT data, if you want proof of dropouts or stale data.

  • with not in the foreground you mean data field on another page?

    If so yes compute is called every second.

    However if your data field stresses the system and your calculation takes longer than a second there could be a drop. When you calculate average yourself both collect the sample and the number of samples (so do not rely on the number of seconds for the latter)

  • However if your data field stresses the system and your calculation takes longer than a second there could be a drop. When you calculate average yourself both collect the sample and the number of samples (so do not rely on the number of seconds for the latter)

    +1

    If so yes compute is called every second.

    They mean when you switch to the watchface/widget loop during an activity (for watches which support that.)

    As I answered, I'm pretty sure the answer is "yes", otherwise a lot of data fields (including my own) would break when you do that. (Plus I tested it myself, above).

  • not only on other page of activity but when I return to watch face

    and it's can be problem, because I should have almost 1s interval