Hello all,
I have a strange problem. I developed a Widget, that uses a background process to grab some data from the sensor.
In the simulator this works fine, but on my Fenix 7s the background process is not called automatically.
It's called, when I show the Widget, either in glance mode or if I go to the full view.
Using SDK 4.0.10, but tried it also with 4.1.0 beta, same effect.
The firmware of the watch is 7.35
I tried to reproduce it with a simple Widget, that only writes a counter to the properties and increases that counter in the background process and write it back in "onBackgroundData"
Same effect, in the simulator it works fine, but not on the watch.
I tought a background process should be called automatically in the background?
For this widget, my expectation was, that the counter increases automatically every about 5 min by one, even if I don't show the widget in the meantime.
Here is my source code, maybe I'm doing something wrong? Any help is very welcome?
Or is there something on the watch to configure, to allow background processing?
App:
(:background)
class MyWidgetApp extends Application.AppBase {
function initialize() {
AppBase.initialize();
}
function onStart(state as Dictionary?) as Void {
}
function onStop(state as Dictionary?) as Void {
}
function getInitialView() as Array<Views or InputDelegates>? {
return [ new MyWidgetView() ] as Array<Views or InputDelegates>;
}
function onBackgroundData(data) {
System.println("onBackgroundData");
getApp().setProperty("MYBG_DATA", data);
WatchUi.requestUpdate();
}
function getServiceDelegate() {
return [new BgbgServiceDelegate()];
}
(:glance)
function getGlanceView()
{
if (Toybox.System has :ServiceDelegate) {
Background.registerForTemporalEvent(new Time.Duration(5 * 60));
}
else {println("no background available");}
return [ new MyGlanceView() ];
}
}
Delegate:
(:background)
class BgbgServiceDelegate extends Toybox.System.ServiceDelegate
{
function initialize() {
ServiceDelegate.initialize();
}
function onTemporalEvent() {
var counter = getApp().getProperty("MYBG_DATA");
if (counter == null) {
counter = 0;
}
else {
counter ++;
}
Background.exit(counter);
}
}
Thanks a lot