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?

  • 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?

    Yes.

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

    Yes.


    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?

    It means if you call registerForTemporalEvent with a Moment, and that Moment is in the past, the background event triggers immediately. e.g. If you register for a temporal event scheduled for any time in 2020, then the event will run immediately (assuming the system clock is correct.)

    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?

    It's saying that onTemporalEvent() (or any other ServiceDelegate function) is guaranteed to finish, but if you call an async function (with callback) from the delegate function, its callback isn't guaranteed to be called.

    e.g. If you call makeWebRequest() from onTemporalEvent(), the responseCallback of makeWebRequest() is not guaranteed to be called.

  • t's saying that onTemporalEvent() (or any other ServiceDelegate function) is guaranteed to finish, but if you call an async function (with callback) from the delegate function, its callback isn't guaranteed to be called.

    e.g. If you call makeWebRequest() from onTemporalEvent(), the responseCallback of makeWebRequest() is not guaranteed to be called.

    so description in documentation  is completely not clear and should be correct, now I know but when I read document it sounds otherwise (shut down process means no process no co callback function)

    It means if you call registerForTemporalEvent with a Moment, and that Moment is in the past, the background event triggers immediately. e.g. If you register for a temporal event scheduled for any time in 2020, then the event will run immediately (assuming the system clock is correct.)

    ok, I "forget" meaning of past :)

  • more questions

    1. if I want to return data from background to app I have 2 ways

    - save it in property/storage

    - return it using BAG.exit(data)

    but if registerForTemporalEvent was called with Duration BAG.exit(data) from inside ServiceDelegate closes background, sure?

    2. documentation for exit(backgroundData) says:

    This method will exit if called by a background process, but will do nothing if called by the main application process.

    So what bag.exit does? ?  Is the same like SYS.exit()  or means "delete all temporary events and stop periodicaly calls  onTemporalEvent"?

  • Terminates the current background process.

    Current means "this one thread called with registerForTemporalEvent "?

    So how can I stop backgrounding started on registerForTemporalEvent  with Duration?

  • So how can I stop backgrounding started on registerForTemporalEvent  with Duration?

    deleteTemporalEvent()

  • 2. documentation for exit(backgroundData) says:

    This method will exit if called by a background process, but will do nothing if called by the main application process.

    So what bag.exit does? ?  Is the same like SYS.exit()  or means "delete all temporary events and stop periodicaly calls  onTemporalEvent"?

    It's like Sys.exit(), but like the doc says, it only exits if called by the background process (and not the main application process.)

    It also provides a way for the background process to send data to the foreground process, as you know.

  • Current means "this one thread called with registerForTemporalEvent "?

    I can't emphasize this enough, but it doesn't really make sense to talk about threads in Connect IQ, as:

    - every process is single-threaded

    - the background *process* and foreground *process* are separate processes which happen to share code, but not memory (e.g. global variables)

  • Current= this_which_call_exit_when_duration_this_one_periodidical

    ... If I call registerForTemporalEvent with Duration(300) at 12:00

    - at 12:05 system creates background and call it's onTemporalEvent and inside it there is exit(true)

    - at 12:10 Will system call onTemporalEvent (despite exit at 12:05, system create "new" background) or I should call again registerForTemporalEvent

    SYS.exit() - kills app, no app no data, BAG.exit makes the same with bag, so there is member inside servicedelegate it will reset and bag.initialise call, right?

    If there is no BAG.exit() system call onTemporalEvent  previous created background but of course is impossible without exit send data to foreground but for timer i can use only  onStorageChanged

    and one more thing, is system kills BAG if I use deleteTemporalEvent()?

  • and next

    - app has background process

    - I run app on sim an everything is ok

    - on device, I run app and background doesn't start - does app have to exit to start background process?

  • Current= this_which_call_exit_when_duration_this_one_periodidical

    ... If I call registerForTemporalEvent with Duration(300) at 12:00

    - at 12:05 system creates background and call it's onTemporalEvent and inside it there is exit(true)

    - at 12:10 Will system call onTemporalEvent (despite exit at 12:05, system create "new" background) or I should call again registerForTemporalEvent

    I don't have :) I've made test