What's the point of starting an app every five minutes in a watch that doesn't support Glance (ie Venu)

Hi, to help finding when a log trace starts when debugging, I've added "Starting app" in the Initialize function.

(:background)
class TeslaLink extends App.AppBase {

    function initialize() {
logMessage("Starting app");
        AppBase.initialize();
    }

To my surprise, the following was shown in the log file on my watch

9:08:04 : Starting app
9:13:03 : Starting app
9:18:04 : Starting app
9:23:04 : Starting app
9:28:04 : Starting app
9:33:05 : Starting app
9:38:06 : Starting app
9:43:06 : Starting app
9:48:06 : Starting app
9:53:06 : Starting app
9:57:15 : Starting app
9:57:47 : Starting app
9:57:47 : stateMachine vehicle_id 1493038771190796 vehicle_state online _need_auth false _auth_done true _check_wake false _need_wake false _wake_done true
9:57:47 : StateMachine: Requesting data
9:57:49 : onReceiveVehicleData: responseCode is 408
9:57:50 : stateMachine vehicle_id 1493038771190796 vehicle_state online _need_auth false _auth_done true _check_wake true _need_wake false _wake_done true
9:57:50 : StateMachine: Getting vehicles list
9:57:51 : onReceiveVehicles:responseCode is 200
9:57:51 : stateMachine vehicle_id 1493038771190796 vehicle_state asleep _need_auth false _auth_done true _check_wake false _need_wake true _wake_done false

I didn't launch the app every five minutes so the watch is itself calling the app Initialize function. I'm guessing it's doing that for every other apps I have installed too. I could see on a watch that support Glance to do this to update the glance data, but what good does it do on a watch without Glance support?

Just curious on why it does that as I find it wastes resources for no apparent gain.

  • Taking into account that (:background) annotation is present in your code snippet I assume that you have added a background process with 5-min frequency into your app.

    Whenever a background process starts, a new instance of the app starts but, unlike the main app instance, it loads only resources annotated with the (:background) annotation.

  • Yes, each time the background runs, initialize()  (and a few other things in the AppBase run).  onStop also runs when the background finishes.

  • Yeah, background process was started for Glance to fetch its data. Is there a way to prevent a background process for spawning if the watch doesn't support Glance?

  • Theoretically, you may have two different getInitialView() methods. One with a declaration of BG process schedule and another - without. You may put 2 different annotations on these methods based on the concrete product ID, and then exclude these methods from the build for the concrete device as described here:
    https://developer.garmin.com/connect-iq/core-topics/build-configuration/#feelingexcluded

    Or you may simply put some boolean flag into device-specific string resources. For some devices it will be true, for others - false. Then, basing on this flag, you may schedule or not background process inside the getInitialView() method.

  • Thanks. That gave me an idea. Using excludeAnnotations, I changed the glance enabled code to this

    (:background)
    class TeslaLink extends App.AppBase {
    
        function initialize() {
            AppBase.initialize();
        }
    
        (:can_glance)
        function getServiceDelegate(){
            return [ new MyServiceDelegate() ];
        }
    
        // This fires when the background service returns
        (:can_glance)
        function onBackgroundData(data) {
            Application.getApp().setProperty("status", data["status"]);
            Ui.requestUpdate();
        }  
    
        (:glance, :can_glance)
        function getGlanceView() {
            Application.getApp().setProperty("canGlance", true);
            Background.registerForTemporalEvent(new Time.Duration(60*5));
            return [ new GlanceView() ];
        }
    :
    :
    
    (:background, :can_glance)
    class MyServiceDelegate extends System.ServiceDelegate {
    
        var _token;
        var _tesla;
        var _vehicle_id;
    
        function initialize() {
            System.ServiceDelegate.initialize();
    :
    :
    
    (:glance, :can_glance)
    class GlanceView extends Ui.GlanceView {
    	
      function initialize() {
        GlanceView.initialize();
      }
    :
    :
    
    

    And made the following monkey.jungle file

    project.manifest = manifest.xml
    base.excludeAnnotations = can_glance
    fenix7.excludeAnnotations = cant_glance

    Breakpoints in the 'glance' code while running as a Venu are disabled and are enabled and hit while running as a Fenix 7.

  • One more question, on the app, background service is only required for glancing. So, is there a way to allow Background permission per devices? So devices without glance won't have that permission? I noticed that for the Venu, although I disable all the ':background' tag in the source file, since the background permission was given, the following happened at compile:

    WARNING: venu: The background permission was enabled but no source code was annotated. The entire application will be loaded as a background process. (background application)

    Yikes.

    Thanks.

  • Unfortunately, no. Permissions can be declared in the manifest file only. 1 manifest = 1 application. So, you need to have totally separate applications in the IQ store with different permissions.

    But I guess you may ignore that warning message. Since you don't have a backgrounding schedule for non-Fenix devices, your "entire" background app instance will never be ever started.

  • If you only want the background to run if in a blance, and at most 1 time, do this.

    in your AppBase, in getGlanceView() do

    Background.registerForTemporalEvent(new Time.Duration(5 * 60));

    and then in onStop(), do

    Background.deleteTemporalEvent();

    One thing to consider, is WatchUi.requestUpdate() may do nothing on devices with liveUpdates=false;

    Also, the background may not run when you are looking at the glance.  It has to be 5 minutes or more since the last time it ran.

  • Not sure I understand what that means

    "Since you don't have a backgrounding schedule for non-Fenix devices, your "entire" background app instance will never be ever started"

  • Glance has to get the live vehicle charge level so it has to run at its 5 minutes interval