Compute() not called if on other screen and data field not visible?

Hi, I assumed - and, if I remember correctly, confirmed by testing some while ago - that compute() is always called each second when in an activity profile that contains the CIQ data field on one of its screens, whereas onShow() would only be called when the screen with that data field is currently displayed.

Now, a user brought to my attention that my app that analyzes power data doesn't seem to have worked correctly for the time he has been on a different screen and comes back, and I was able to replicate that.

The only explanation I have now is that compute() is under some circumstances either not called or aborted before regularly completing when the data field is not displayed. Admittedly it's a very computation intensive app, so I am happy that Garmin let's me do those calculations when the data field is displayed, but I was wondering whether others have observed this or what Garmin's explanation for this might be? Has something changed recently? Or am I wrong with about the intended behavior of compute and onShow?
  • What device? What firmware? Are you sure you're doing nothing in onUpdate() that impacts what you do in compute()? (you mention onShow(), but it's onUpdate() that get's called every second when the field is visible, and not called when it's not)
  • Thanks for the reply! - and yes, sorry, I meant onUpdate().

    Replicated the issue on Edge520/820/1000 with current firmware last week and triple-checked the code now ... I am updating an array of peak power values for intervals from 1s up to 3hrs in compute() and then calculating and displaying the current ride's peak power in onUpdate(). The final bit of calculations should of course ideally be done in compute(), but in order to reduce memory usage it incorporates scaling to the current display size of the data field and that's why it ended up in onUpdate() after refactoring the code - the intended design was that if the array has correctly been updated while not on screen, all the changes would simply be reflected the first time onUpdate() is called after the user changes back to that screen.

    I will check again later and may be add some debug code to count and show that compute() is really called and that it's just a bug on my side... Thanks for your help.
  • A quick way to check is keep a counter of the # of times compute() is called and just display that counter on the screen in onUpdate(). Move away from your DF for a minute, go back, and the counter should have incremented by 60.