Is there a problem with temporal events in a widget. I'm trying to get an event to fire at the end of each day, but I tried first to test with an event that fires near the end of each hour. This is a snapshot of the code;
Is there a problem with temporal events in a widget. I'm trying to get an event to fire at the end of each day, but I tried first to test with an event that fires near the end of each hour. This is a snapshot of the code;
Hi Trudelta, I can't say why your code isn't working, but here's what I do in my app "Hourly Alert!" https://apps.garmin.com/en-US/apps/9c11d041-09bf-4613-9381-f9bc9b19dac4
var clockTime = System.getClockTime();
var atime;
var minutes = clockTime.min;
var seconds = clockTime.sec;
seconds += (60 * minutes);
atime = 3600 - seconds;
atime += Time.now().value().toNumber();
atime = new Time.Moment(atime);
try {
Background.registerForTemporalEvent(atime);
System.println("----Background set!----");
} catch (e) {
//This should only happen when the temporal event has been delayed. For example, a run
//activity could delay this event. So, just register for atime + 3600 seconds.
var SIXTY_MINUTES = new Time.Duration(60 * 60);
Background.registerForTemporalEvent(atime.add(SIXTY_MINUTES));
System.println("----Error, but recovered, and set background for atime + 3600----");
} finally {
}
I removed a few app specific things from the code, so I'm not 100% sure this will work on the first time, but it should give you a start.
Where are you registering the event? I'm doing it in the App getInitialView() method. It doesn:t work. Sometimes the event fires when I activate the widget for viewing.
When you register a temporal event, it may not run when you expect, but only run when resources are available. For example, if you are running a device app at the same time, your background service won't run. But if you close the device app and go right to your widget, you'll see it run right away. When you see it run can vary based on if you have a glance view and if the devices supports live updates for glances.
I put this code in a function, and call it from these functions:
• onTemporalEvent() (setting for the next hour),
• onAppInstall(),
• onAppUpdate(),
• onLayout(dc).
Some users have complained that they can't uninstall my app, probably because there's always a temporal event in place, messing with the uninstall process. I recently added a setting so that users can manually turn off the temporal event if they are having trouble uninstalling the app.
Also, when a user opens the widget I made, it tells the user when the event was last run. That way, I know if the event has been working properly.
You may want to try requestApplicationWake (if you haven't already), so that you can get immediate results about if your app is working correctly, instead of having to println everything.
The problem with uninstalling isn't the temporal evet. The Connect IQ Mobile app has issues in that area, and when I hear about it from a user, I ask them to use Garmin Express instead.
Or just display a timestamp in the app for the age of the data received. I do that in my weather widgets to show how "fresh" the data is.