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!
  • Yes it the sim, once an app with a background process is run, it keeps running the background, even if different apps or a different target is used.
  • Former Member
    Former Member over 6 years ago
    Temporal events are not allowed to run for 5 minutes since the last time one ran. This means that if your application has never run a temporal event before (initial install) an event can run immediately. If you register with a duration, it will not wait the duration in this case, but will run immediately, and then again after the specified duration (and repeat until deleted). If you register for events every 5 minutes, you should always have data that is less than 5 minutes old unless events are blocked by something else in the system such as running a full Connect IQ application. If you do run an application for longer than your temporal period, then your event time will be "expired", and the background event will run as soon as possible after the application is closed.
  • Are you having trouble downloading the .zip? I just tried the link in the first post and it seems fine. There's also a link right to the .zip in the blog post. Which are you having trouble with?


    Hi,

    I can not download the .zip file. Could you please email me the zip to my PM? Thank you in advance.

    Matthias
    Forget about it. It worked.
  • He Guys.

    Talking about background processes. Some users that use my App's, complain that they get messages (fi. steps goals), when the app is running. If they do not press the back button the app stops recording. Can I do something about it). Can I act on messages in my App.

    Kees
  • Do you mean the standard goal and move things? That's a setting on the watch where you can disable them. There's nothing you can do in a CIQ app to stop them.
  • Former Member
    Former Member over 6 years ago
    If you are stopping your recording in the onHide() method of your view, you should try change this. When a native view appears during your application, this method will be called for your top view.
  • Hi Brian.

    Thanks. And in the onshow() I can start recording again right?
  • Is there a reason you want to start/stop the recording? Are you doing a manual or auto pause in the recording?
  • Former Member
    Former Member over 6 years ago
    I think I did not communicate very clearly.

    I would not recommend stopping your recording in the onHide() of your application because this can cause the application to stop recording when things like step goals appear, which can occur. You will want your application to continue recording when the system is displaying something over top of your application to avoid gaps in the data.
  • This is the same kind of thing as where you were calling setEnabledSensors() in onShow() in the other thread. You don't want to be stopping/starting recording when you get a goal alert, notification, etc.