Fails to compile watchFaceApp with background using strict typechecking

Hi all,

I'm trying to get strict/informative type checking to work in a watch face application having a background process.

my bare-minimal code is:

import Toybox.Lang;
import Toybox.System;
import Toybox.Application;
import Toybox.WatchUi;
import Toybox.Time;
import Toybox.Graphics;

(:background)
class FromoxApp extends Application.AppBase
{
    function initialize() {
        AppBase.initialize();
    }

    function getInitialView() as Array<Views or InputDelegates>? {
        Background.registerForTemporalEvent(new Time.Duration(5 * 60));
        return [ new FromoxView() ] as Array<Views or InputDelegates>;
    }

    function getServiceDelegate() as Array<System.ServiceDelegate> {
        return [ new FromoxBackground() ] as Array<System.ServiceDelegate>;
    }    

    function onBackgroundData(data as Dictionary?) {
        var status = (data != null) ? data["status"] : "?";
        System.println(format("onBackgroundData, status = $1$", [status]));
    }
}

function getApp() as FromoxApp {
    return Application.getApp() as FromoxApp;
}

(:background)
class FromoxBackground extends System.ServiceDelegate
{
    function initialize() {
        ServiceDelegate.initialize();
    }

    function onTemporalEvent() as Void {
        Background.exit({ "status" => "ok" } as Dictionary<PropertyKeyType,PropertyValueType>);
    }
}

class FromoxView extends WatchUi.WatchFace
{
    function initialize() {
        WatchFace.initialize();
    }

    function onLayout(dc as Dc) as Void {
        setLayout(Rez.Layouts.WatchFace(dc));
    }

    function onUpdate(dc as Dc) as Void {
        View.onUpdate(dc);
    }
}

However, I always get the following error:
WARNING: fenix6pro: [...]\FromoxFace\source\FromoxAppTest.mc:18: Value 'FromoxView' not available in all function scopes.
WARNING: fenix6pro: [...]\FromoxFace\source\FromoxAppTest.mc:18: Value 'initialize' not available in all function scopes.

(not that in strict type checking this is not a warning anymore but an error!)
What I get from this error is that some functions in the background app tries to call the view, which is not a background class.
It looks like I have to annotate ALL classes to be background-visible.

In a default/off/gradual type checking this is not an issue and the compiler finds its way.

Does anyone know how to properly code a face app with a background process AND compile it with strict type checking?

Many thanks in advance!

  • To all:
    I finally found the answer myself:

    in the last paragraph of "developer.garmin.com/connect-iq/monkey-c/monkey-types/",
    it states how to disable background checking using: :typecheck(disableBackgroundCheck)

    This was not clear from "developer.garmin.com/connect-iq/monkey-c/annotations/" .