VERY Simple sample of a watch face with a background process.

This one really doesn't do much. It displays the time, an indication if it's on a device that supports background processes (you can see how that's checked in the App Class), The count of the times the background process has run, and the data returned from the background. It does cache data in the object store, so after the first time the background runs, it will have data.


The background process is a Temporal event, and runs every 5 minutes. All the background does is return a string with a time stamp (HH:MM). There are a number of Sys.println() calls to see what's going on. If you have a watch that supports background processes (f5's,chronos,935,735,va-hr), create a <myapp>.txt in logs to catch the println() calls, as you see kind of a neat thing where those that come from the background are marked as such!

This runs in the sim can you can use the code to build a sideload. In addition to devices that support background processes, I included the fenix 3 as a target so you can see how it works on a watch that doesn't.

if you have questions about the code, just ask!
  • You can also look at a much more recent example watch face with a background service and a bunch of other things:
    https://forums.garmin.com/developer/connect-iq/f/discussion/349473/simple-example-wf-that-shows-a-bunch-of-things

    It's got a very simple background service that just returns the time as a string you can start with for your data field.

  • Another thing you might be seeing is when you do the registerForTemporalEvents, that doesn't mean the background runs right away.  If you've ever ran the app before, it's still on the 5 minute (from your code) interval, so it may not actually run for another 5 minutes.

  • That if doesn't make sense IMHO. You check if there's already an event. If there IS, then you register another one (which IMHO will not be effective 'cause you haven't removed the existing one), but more importantly if there ISN'T then you don't do anything. So there will never be any event registered.

  • I always just do the registerForTemporalEvents when an app starts.  While it might have been done in the past, the time could have changed if the interval is configurable.  For example, the default could be every 15 minutes, but the user changes it to every 30 minutes.

    This is what I do with any of my apps with a background service - WF/Widget/DF

  • I'm pretty confident this isn't what you do, if you READ my previous comment AND the comment it responds to (the actual code example) and look close then you'll see that the != should be == IMHO.

  • Like I said, I just always do the register as doing any check isn't needed at all.

    Have you looked at who started this thread 7 years ago?

    Since that time I've written and published a number of apps with a background service, and posted code for a few examples, so you can see exactly what I do...

  •  Now it is possible to call makewebrequest from the data field main app on system7 devices (connect IQ ver 5). That is so much easier than having to mess around with background. Not many system 7 devices out there though, would be amazing if foreground web request was available in all devices. Does anyone know if the plan is to allow the same for watch faces? 

  • I doubt it.  What I've moving towards today is to publish complications in a "widget" (with a background service) and then show them in a watch face.  For things that may require an API Key, that also means you only need to set it once and you can see data in watch faces, the widget itself with a press, or even with FaceIt watch face that "discovers" what's published by CIQ apps on the device

    So, for example, I have a watch face in the store that by default shows the weather from Toybox.Weather.  If you are on a device that supports complications and have one of my weather widgets installed, you can select the data from another source - OWM or Weather Underground. And I can provide info on how to access the complications from your watch face.

  • I agree that "if" statement doesn't make sense.  I did change it to == and tested but it still didn't work.  The simulator crashed actually.  

  • So it seems like once you have a working background service you can use it for any type of app ?  I'll dive into your example app and see what I can do. Thanks Jim.