Screen updates only on a key event or touch but not every second or even every minute. How can I change the update frequency?

Thanks to your support I managed to Beta Launch my first app today! Thanks for all the helps so far. But upon using it on my actual garmin device I noticed that the screen only updates when I tap it (activating functions that explicitly call WatchUi.requestUpdate();) It actually didn't do this in the simulator either, but I thought it would solve itself on the device.

Elsewhere on the discussions boards I read it should update every second, at the very least every minute. But it does neither. Could it be that I have accidently overwritten the basic screen update settings? 

Any suggestions on how to get it to refresh the view every second (at minimum)? Thanks in advance

-------------

My code looks like this, it is pretty basic I guess.

- onLayout calls on the basic background layout which I set to white

- onShow and onHide are empty

- onUpdate holds a reference to other functions that draw the view

-------------

import Toybox.Graphics;
import Toybox.Lang;
import Toybox.System;
import Toybox.WatchUi;
import Toybox.ActivityMonitor;
import Toybox.Activity;
using Toybox.UserProfile;

class MatchView extends WatchUi.View {

    private var UI = getApp().getUIHelpers();
   
    var matchStarted = true;                        //True is me; false is opponent  
    var matchWinner = false;                        //False is not finished; other PLAYER_1/PLAYER_2  
    var firstService = true;
    var fore_backhand = null;
    var net = false;
   
    function initialize() {
        View.initialize();
    }

    // Load your resources here
    function onLayout(dc as Dc) as Void {
        setLayout(Rez.Layouts.MainLayout(dc));
    }

    // Called when this View is brought to the foreground. Restore
    // the state of this View and prepare it to be shown. This includes
    // loading resources into memory.
    function onShow() as Void {
       
    }

    // Update the view
    function onUpdate(dc as Dc) as Void {
        // Call the parent onUpdate function to redraw the layout
        View.onUpdate(dc);
        if (matchWinner != false) {
            finalView(dc);
        }
        else {
           
            drawGameScore(dc);
            drawHeartRate(dc);

            if (getApp().getStatistics().statisticsMode != 0) {
                drawService(dc);
            }
           
            if (fore_backhand != null){
                drawForeBackhand(dc);
            }

            if (net == true){
                drawNet(dc);
            }
        }

        updateTime(dc);
    }

    // Called when this View is removed from the screen. Save the
    // state of this View here. This includes freeing resources from memory
    function onHide() as Void {
    }
  • Onely watch faces and data fields have onUpdate() called automaticly.  For device apps and widgets, you usually want to start a timer and have it call WatchUp.requestUpdate() on a regular basis.

  • Interesting! That explains why it didn't happen so far. Would you have an example of some code that accomplishes this?

    I'm having trouble envisioning how this would work. Would I start a function that includes a timer when I start the activity? Let it run down 500 ms and then call itself again?

  • In your view's initialize(), create and start a timer for 1 second for example

    		var timer= new Timer.Timer();
    		timer.start( method(:onTimer), 1000, true );

    And the onTimer callback is nothing more than

    function onTimer() {WatchUi.requestUpdate();}

  • It seems deceptively simple, but I cannot seem to get around this error being thrown

    Invalid '$.Toybox.Lang.Method() as Any' passed as parameter 1 of type '$.Toybox.Lang.Method() as Void'.

    I've implemented it like this now... 

    ------------------

        function initialize() {
            View.initialize();
            var timer = new Timer.Timer();
            timer.start(method(:timerCallBack), 500, true);
        }

        function timerCallBack() {
            WatchUi.requestUpdate();
        }
  • See the Timer sample in the SDK for an example of what to add for type checking.

  • As always it takes a night of sleep! The function timerCallBack needed to be specified as Void. I didn't look in the example but in the API documentation this is not mentioned either.

    Thanks again though! It is much appreciated