background process

I'm sorry  formatting text is treated as abuse, so clear text maybe

According to developer.garmin.com/.../Background.html


Temporal background events may be registered to run at a specific point in time by providing a Moment at which the event should trigger

A. e.g. when I call at 22:10 registerForTemporalEvent("at 2021-02-29 05:43") (even after 6 hours) system calls onTemporalEvent in this moment in future?


or may be registered to run at a periodically by specifying an interval Duration.

Is does mean that I don't have to call registerForTemporalEvent periodically it will run like timer?

B. e.g. when I call registerForTemporalEvent(new TIM.Duration(300)) at 22:05 system calls onTemporalEvent every 5 minutes (22:10, 22:20...)?


if a temporal event is scheduled for a time in the past, the event will trigger immediately.

what does mean? I want schedule like in A and system call onTemporalEvent  immediately?


and next, developer.garmin.com/.../ServiceDelegate.html:

ServiceDelegate is a class used to service Background events.

This class is used as the main entry point for background processes. A callback function within the delegate can be used to initiate other system events (e.g. Communications), but only the delegate function is guaranteed to complete. The Background process may be shut down at any time to handle higher priority processes.

What does exactly mean: may be shut down? System won't call onTemporalEvent? App can't call registerForTemporalEvent?

  • for this up I've made https://forums.garmin.com/developer/connect-iq/i/bug-reports/background-process-doesn-t-start-on-device

    please answer: is system kills BAG if I use deleteTemporalEvent()?
    it's important I don't want to have background process if I don't it when app is not run so I want to know how to kill it.

  • is system kills BAG if I use deleteTemporalEvent()?

    Based on the documentation, I would say no.

    it's important I don't want to have background process if I don't it when app is not run so I want to know how to kill it.

    You could have a key in Application.Storage called isAppRunning (or something).

    When the foreground app starts, you set it to true.

    When the foreground app stops, you set it to false. The background process should get an onStorageChanged() notification, and you can exit at that point.

    Of course, this assumes:

    1) You have a way to tell the difference between the foreground process and background process. (Which you do: set a flag in getInitialView() or getServiceDelegate())

    2) You believe that onStorageChanged() will be called for background processes. Since I don't develop apps with background processes, I can't say for sure, but based on reading the docs and what others have said, I believe that it will.

     

  • If the main app is a device app, I don't think the background runs when the  main app runs - only when the main app isn't running.  This sounds like it would prevent the background from ever running.

  • I answered in https://forums.garmin.com/developer/connect-iq/i/bug-reports/background-process-doesn-t-start-on-device

    Ok, it means:

    - if registerForTemporalEvent  with Duration (periodical)

    - and don't want to allow background run when app exit

    - can't call deleteTemporalEvent by app

    - instead of I have to e.g. setProperty("killBAG", true) in place when I know that is end of app and add code do SD

       function onTemporalEvent()
        {
            if(APP.getApp().getProperty("killBAG"))
            {
                SYS.println("onTemporalEvent kill BAG");//not call on sim
                deleteTemporalEvent ();//no more onTemporalEvent
                BAG.exit(null);//no return data
            }else
            {
                SYS.println("onTemporalEvent keep BAG");
                BAG.exit(true);
            }         
        }

    correct?

  • or simple resign from duration and in

    onBackgroundData

    call again registerForTemporalEvent (Moment)

  • If the main app is a device app, I don't think the background runs when the  main app runs - only when the main app isn't running.

    Thanks for the clarification! But then:

    it's important I don't want to have background process if I don't it when app is not run so I want to know how to kill it.

    Doesn't that mean that the BG process will never run, if it's prevented from running when the app isn't running?

    Or maybe I'm misunderstanding the reqs here.

  • The problem is that app in foreground drains battery so I thought to remove timer and replace it background process. My app need to run for e.g. 8h and I don't want to tell user to charge watch every day and most user will "eat me for breakfast" for that draining. It has to consume battery on the same level like watch face or less because I plan to not draw anything - it runs during a sleep.

    I thought that most expensive is drawing but I can see that not so I'm looking for solution this problem.