how to ensure custom code keeps tracking even when onMenu or onHide

I have a question.. (hence I am writing this .. LOL..)

Anyways - i am writing and app and I have some custom code which I want to be executed at every second. This custom code is to keep track of Laps. However that I have noticed when I go into the app's menu, the custom code does not get called (the custom code/function is embedded inside onUpdate)

Since when I go into the MENU system, onUpdate doesn't get called. so.. that's a problem.

IS there a way to enable the custom code to always run in the background?
  • Former Member
    Former Member over 9 years ago
    OnUpdate is called with the display updates for your view. Therefore, if your view is not visible, onUpdate calls will stop.

    If you want to run something continuously in the background you would need to set up a Timer.
  • function onLayout(dc) {
    Timer1 = new Timer.Timer();
    Timer1.start(method(:callback1), 1000, true );

    }


    I do have a timer running in the background.

    function callback1() {
    Ui.requestUpdate();
    }



    or is it that I need to have something in the callbackfunction?

    the custom code for laps is called customlaps(). insert it into callback1?
  • Former Member
    Former Member over 9 years ago
    You will need to put the call to your lap tracking function in the callback. Calling Ui.requestUpdate() will just ask the device to update the display, which will still only update the view that is visible.
  • Thanks a bunch Brian.. I think I got it..
    At least it looks that way in the simulator.