How to re-open a Connect IQ app from a background process?

433 Views Asked by At

I want to write a mood tracker for my Garmin Fenix, so I want the app to pop up after some time interval, vibrate, and ask me for my current mood. Of course, I don't want to have the mood tracker in foreground all the time, so I'm looking for a way to re-open my app from a background task.

I found two modules which seem like they could achieve this, Timer and Background. Background can pass back data to the app after some time, but it can't vibrate and data transfer only takes effect once the app is manually re-opened. Timer doesn't seem to have much effect at all, once the app is closed – at least in the simulator.

What's the best way to re-open my app after a specific period of time?

1

There are 1 best solutions below

1
On

From what I understand you could do as followes:

You want to use [requestApplicationWake][1].

in the onStop() method you can register a temporalEvent.

Background.registerForTemporalEvent( 10 * 60 ); // 10 mins is the min

Then create this class that will be called when the event is triggered.

using Toybox.Background;
using Toybox.System;
using Toybox.Application.Storage;

(:background)
class BackgroundTimerServiceDelegate extends System.ServiceDelegate {

    function initialize() {
        ServiceDelegate.initialize();
    }

    function onTemporalEvent() {
        // do whatever processing you need and then serve the popup
        Background.requestApplicationWake("do you want to open the app?");          
    }
}