I have written a small widget type app that fetches some data from an api and displays data.
My latest addition is to fetch data in the background and if the data is above a certain threshold.
This all seems to work, even the backgroud process (logging that it gets the values etc.)
But it seems the: Background.requestApplicationWake("value is high, show widget?") does nothing, no dialog, no exception in the log, nothing.
I thought I could call this in the background to ask the user to open the widget/app again.
I am testing on a physical Venu watch, and in the simulator as well.
My BackgroundDeviceTransactionDelegate calls the restoreFromBackground function, but nothing seems to happen.
// https://forums.garmin.com/developer/connect-iq/f/discussion/252923/requestapplicationwake-in-onrecive
(:background)
class BackgroundTimerServiceDelegate extends System.ServiceDelegate {
var _transaction;
function initialize() {
ServiceDelegate.initialize();
}
function onTemporalEvent() {
fetchData();
}
function fetchData() {
var deviceId = App.getApp().getProperty("device");
if(deviceId != null){
var backgroundDeviceTransactionDelegate = new BackgroundDeviceTransactionDelegate(self);
_transaction = new BackgroundDeviceTransaction(
backgroundDeviceTransactionDelegate,
deviceId
);
_transaction.go();
}
}
function restoreFromBackground(){
Background.requestApplicationWake("value is high, show widget?");
Background.exit(null);
}
}
My main app looks like this:
using Toybox.Application;
using Toybox.WatchUi as Ui;
using Toybox.Application as App;
(:background)
class MyApp extends Application.AppBase {
function initialize() {
AppBase.initialize();
}
function onStart(state) {
}
function onStop(state) {
System.println("onStop");
}
function getInitialView() {
if(!System.getDeviceSettings().phoneConnected) {
return [new ErrorView("Connect to phone") ];
} else {
// Register for background events:
Background.registerForTemporalEvent(new Time.Duration(5 * 60));
return [ new DeviceView(), new ResetAndSelectOnTapInputDelegate() ];
}
}
function onSettingsChanged() {
Ui.requestUpdate();
}
function getServiceDelegate(){
return [new BackgroundTimerServiceDelegate()];
}
}