Watch Face, Background makeWebRequest

Hi,

I have faced with very unexpected behavior when I'm making a web request from a temporal event.
I thought it is a system limitation, that it is impossible to invoke a background delegate frequent than once in 5 min.
But it turns out that on some devices it happens every second or even a bit faster. Simulator and my own device (F5 plus) behave totally fine but in a very rare case, on my users' devices onTemporalEvent() method is invoked as a machinegun.

The background initialization method pretty standard, just as in documentation:


function InitBackgroundEvents()
{
    var FIVE_MINUTES = new Toybox.Time.Duration(5 * 60);
    var lastTime = Background.getLastTemporalEventTime();
    if (lastTime != null)
    {
        var nextTime = lastTime.add(FIVE_MINUTES);
        Background.registerForTemporalEvent(nextTime);
    }
    else
    {
        Background.registerForTemporalEvent(Time.now());
    }
}

And InitBackgroundEvents() being called from two methods:
function getInitialView()
function onSettingChanged()

So, the question. How does it happen that only on a small number of devices temporal event being invoked once in a second and how to avoid this?
Does anybody have the same experience?

  • Is there a reason you need to know the last time the background ran and try to change the schedule, or can you just register the temporal event with something like a 5 minute duration so it just runs every 5 minutes?

  • I cannot say for sure, but I do vaguely remember something about the Duration being part of the issue and not very reliable.

  • It's actually all I use in watch faces and widgets and never had an issue.

    There are times a background wont run based on available resources, but that happens no mater how the BG is scheduled

  • Thanks, everyone!

    Looks like documentation is misleading and I need to implement last-run myself, but that's fine. Just run every 5 min is not enough - it is too frequent. I actually need once in an hour, unless something changed, like settings and in this case, better to refresh as soon as possible. 

    But the more I think of the original issue, the more it looks like a bug in makeWebRequest, in some specific version of framework or sdk.