Acknowledged

Timer can't call hidden function (Symbol Not Found Error)

import Toybox.Graphics;
import Toybox.Lang;
import Toybox.Timer;
import Toybox.WatchUi;

(:glance)
class FooGlanceView extends WatchUi.GlanceView {

    private var mTimer as Timer.Timer?;

    public function onShow() as Void {
        mTimer = new Timer.Timer();
        mTimer.start(method(:timerCallback), 1000, true);
    }

    public function onHide() as Void {
        log("g.onHide");
        if (mTimer != null) {
            mTimer.stop();
            mTimer = null;
        }
    }

    hidden function timerCallback() as Void {
        WatchUi.requestUpdate();
    }

    public function onUpdate(dc as Dc) as Void {
        // Call the parent onUpdate function to redraw the layout
        View.onUpdate(dc);
        var text = "whatever";
        var width = dc.getWidth();
        var height = dc.getHeight();
        var font = Graphics.FONT_XTINY;
        var justification = Graphics.TEXT_JUSTIFY_CENTER | Graphics.TEXT_JUSTIFY_VCENTER;
        dc.setColor(Graphics.COLOR_WHITE, Graphics.COLOR_BLACK);
        dc.clear();
        dc.drawText(width/2, height/2, font, text, justification);
    }

}

The above code gives the following error:

Error: Symbol Not Found Error
Details: Failed invoking <symbol>
Stack:

Encountered app crash.

Note: there's no actual stack.

I found out that the reason is that the callback for timer is private. IMHO this is a bug, 'cause it is known at the place where it is used (mTimer.start(method(:timerCallback), 1000, true);), so the reference should be known later when the timer want s to use it.

SDK: 4.1.4

Parents Comment Children
No Data