Complete
over 4 years ago

ACROPOLIS-2652

Background event system does not work

It seems the backgrounding system is broken at least on several systems (in my case Fenix 6). It is very easy to reproduce, please follow the steps I am describing below.

What I am trying to achieve: I want to create a widget that gets activated every 10 minutes, collect data via a sensor listener, and gets back to sleep until the next temporal event is triggered.

What I do:

  • I am registering my temporal event in method getInitialView() to start as soon as possible

            // ...
            Background.registerForTemporalEvent(Time.now());


  • I am registering my sensor listener in my service delegate method onTemporalEvent() when it gets called

  • if a temporal event gets triggered, i am restarting my temporal event at the time Background.getLastTemporalEventTime() + 5 minutes in method onStop()
     
          Note: I am aware that I can use recurring events that get triggered periodically. I used them, but they have the same effect. Why I am using the restarting option here is so i can clearly document what happens

            if (LastTemporalEvent != null) {
                    var NextEvent            = LastTemporalEvent.add(FIVE_MINUTES);
                    Background.deleteTemporalEvent();
                Background.registerForTemporalEvent(NextEvent);
            }
            else    {
                   Background.registerForTemporalEvent(Time.now());
            }


My problems:

  • it seems the background process is not triggered as it is supposed to. Sometimes it does, maybe an hour after it i should have been. But it seems not reproducable when it will.
       
  • IF (!) the background process gets started, using the sensor listener in my delegate doesn't give me 30 seconds as it is supposed to do, but only 1 or 2 (if at all). Yes, I am aware that the 30 seconds period can be cancelled at any time by the system, but the way that it always gets cancelled almost immediately renders sensor listeners useless in background processes.
    It can be argued that instead of a listener you can use the SensorHistory, but SensorHistory is not complete when it comes to some data, HRV for example.


One thing that seems very important here is that everything runs perfectly in the Simulator, so that's at least an indicator that my coding isn't completely wrong, I think.


Here is what happens when I generate text output on my watch (some remarks in [ ]):

onStop at 10:37:37
Temporal event NOW registered at 10:37:37
Next background event at 10:37:39
View initialized
Sensor listener registered at 10:37:39
Getting sensor data...1 seconds
onStop at 10:37:43
Next background event at 10:42:39
onStop at 10:37:44
Next background event at 10:42:39
[up to this point, I started the widget to initialize the background timer. Next event should be called at 10:42:39...]
Sensor listener registered at 11:44:37
onStop at 11:45:18
Next background event at 11:49:37
[...but it wasn't. In fact the background process was sleeping for over 1 hour, then registered the sensor listener but never executed the listener once. Then the next background event was scheduled but never executed...]



Because this issue can affect every app that uses the backgrounding system, this is in my opinion a high priority issue that should be solved as quick as possible!

If you need more info, please let me know. Thanks!

Parents
  • Hi cmehmen, nothing shown in the crash logs. I let my widget run for the last weeks and write every callback into a text file. The result is that the callback is called rarely, sometimes only every few days...

Comment
  • Hi cmehmen, nothing shown in the crash logs. I let my widget run for the last weeks and write every callback into a text file. The result is that the callback is called rarely, sometimes only every few days...

Children
No Data