class MyApp extends App.AppBase
{
function initialize() {
AppBase.initialize();
}
hidden var _M_timer;
function onStart(params) {
_M_timer = new Timer.Timer();
_M_timer.start(self.method(:onTimer), 60000, true);
}
function onStop(params) {
_M_timer.stop();
_M_timer = null;
}
function onTimer() {
Ui.requestUpdate();
}
}
_M_timer.start(new Lang.Method(Ui, :requestUpdate), 60000, true);
travis.vitek could you please guide me when the timer should be set? On initialize or onLayout?
To make sure it is always started just once and not repetitively (e.g. when the watch face disappears and appears again)?
How will they affect it? That a timer in low power might be ignored? Will it run after the watch leaves the low power mode?
I just want to set a timer that hourly updates a location twice a day sunrise and sunset. But no problem if it will be a little later. It should just not skip completely.
Is to set it in initialize for such use case ok?
I use background service for data loading and it would be too complex for such a simple task. It already hits memory limits, so it would need to iterate through 3 background tasks. And it needs to work for devices without the background service as well.
They actually suggest that the Timer should be used for updating position: https://developer.garmin.com/connect-iq/api-docs/Toybox/Position.html#getInfo-instance_function
If it crashed in low-power mode, it would be completely useless, as you can not control it.
I think the timer might rather be skipped than crash. Great would be if it runs once back from low-power though.
Great would be if it runs once back from low-power
Again, look at onEnterSleep and onExitSleep
That's how you can see if you're in low or high power mode.
You are right. Not even possible to set the timer in the initialize of the watch face. So everybody who needs timers in the watch face basically needs to implement the same logic of pausing, resetting and calculating new time for the timer each time it fires or the watch wakes up. Lame.