1

Trying to request a webrequest in the background, and trigger an application wake when it finishes. The example code works, but it's impossible to wake the app from a callback:

using Toybox.Background;
using Toybox.Communications;
using Toybox.System;

(:background)
class BackgroundService extends System.ServiceDelegate {

    function onTemporalEvent() {       
        Background.requestApplicationWake("do you want to open the app?"); 
        Background.exit(null);
    }
}

This does not work:

using Toybox.Background;
using Toybox.Communications;
using Toybox.System;

(:background)
class BackgroundService extends System.ServiceDelegate {

    function onTemporalEvent() {
        Communications.makeWebRequest(
            "https://jsonplaceholder.typicode.com/todos/1",
            {},
            {},
            method(:responseCallback)
        );
    }

    function responseCallback(responseCode, data) {
        Background.requestApplicationWake("do you want to open the app?");       
        Background.exit(null);
    }
}
David Karlsson
  • 9,396
  • 9
  • 58
  • 103
  • I would say to try the Garmin Connect IQ forums, but I see you already have https://forums.garmin.com/developer/connect-iq/f/discussion/252923/requestapplicationwake-in-onrecive – Mark H Mar 07 '21 at 02:20
  • It looks like you'd have to check/set a variable in onTemporalEvent and run requestApplicationWake OR makeWebRequest depending on that variable's value. That would make the minimum temporal event period for your app twice what the normal minimum is... – Mark H Mar 07 '21 at 02:35
  • Oh, kind of a nasty fix may be to poll for a variable change in your onTemporalEvent function, waiting for responseCallBack to set it. Once you see the change, you run the requestApplicationWake and Background.exit calls. This in effect turns the asynchronous makeWebRequest call into a synchronous/timeout call. – Mark H Mar 07 '21 at 02:41

0 Answers0