Reset the background timer at app start

Hello there,

I'm not so optimistic but is it true that there is no way to reset background timer, at least at each app start because I need to do OAuth at the start and as I use a datafield the only way is to use a background event (and the app has no sense without the distant data). I've tried with a paired edge 520 with an iPhone  XS and the prompt for authentication  takes a lot of time


If it is not possible for the moment, will Garmin plan to improve that in the near future?


Thanks in advance


  • There are a few recent threads where I talk about this.

    What you want to do is delete the temporal event in onStop() but only if you're NOT running in the background.  Then the next time you start and register the temporal event, it will run right away if it's been more than 5 minutes.

  • Thanks Jim, I've already done that but I'm not sure how to stop app on my device it is new for me
    here is my AppBase

    using Toybox.Application as App;
    using Toybox.Background;
    using Toybox.System as Sys;
    using Toybox.WatchUi as Ui;
    using Toybox.Time;
    using Toybox.UserProfile;
    using Toybox.PersistedContent;
    using Toybox.System;
    
    class KronosApp extends App.AppBase {
    	var inBackground=false;
        
        function initialize() {
            AppBase.initialize();
        	if(Toybox.System has :ServiceDelegate) {
        		Background.registerForTemporalEvent(new Time.Duration(5 * 60));
        	} else {
        		Sys.println("****background not available on this device****");
       		}
          }
    
        // onStart() is called on application start up
        function onStart(state) { 
        }
    
        // onStop() is called when your application is exiting
        function onStop(state) {
        	if(!inBackground) {
        		Background.deleteTemporalEvent();
        		System.println("stop");
        	}
        	
        }
        
        //! Return the initial view of your application here
        function getInitialView() {
        	var Kview = new KronosView();
            return [ Kview];
        }
        
        function onBackgroundData(data) {
    		System.println("onbg "+ data);
            Ui.requestUpdate();
        }    
    //
        function getServiceDelegate(){
        	inBackground=true;	
            return [new JsonBackground()];
        }
    
    
    }