Hi,
I want to implement a widget with a nagging feature like the hydration widget. I need four events to trigger the background process:
1. registerForTemporalEvent(time)
2. registerForActivityCompletedEvent
3. registerForSleepEvent
4. registerForWakeEvent
I am wondering how I can register register them? Currently I do it this way:
function getInitialView() {
if(Toybox.System has :ServiceDelegate) {
// read the setting naggingFrequency: 1h=3600, 2h=7200, 4h= 14400
var nag = Application.getApp().getProperty("naggingFrequency");
if (nag > 0) {
Background.registerForTemporalEvent(new Time.Duration(nag));
}
Background.registerForActivityCompletedEvent();
Background.registerForSleepEvent();
Background.registerForWakeEvent();
} else {
System.println("No BG Data available");
}
return [ new MyView(), new MyDelegate() ];
}
Furthermore I am wondering how I can prevent the main app from starting during the DND times.
It it possible like this?
function onTemporalEvent()
if (!dnd) {
Background.requestApplicationWake("Launch Cool App?");
}
Background.exit(null);
}
function onSleepTime() {
dnd = true;
}
function onWakeTime() {
dnd = false;
}