Check if app is displayed as GlanceView?

First some comments about the app itself...
It's a widget and has a large code base for a web API. That's why th e glance view only uses a small set code to display the glance view. This way I can keep the memory usage low to get glance view working.

But when the glance view is shown and I change app settings in ConnectIQ app, the onSettingsChanged() is called in the app.
In that case, the whole app code is loaded, not only the code defined wth (:glance). That crashed the app because the memory usage is to high for the glance view.

Can I somehow check in onSettingsChanged() if the app is currently in glance mode?
Then I can perhaps prevent using the API module to prevent the crash.

  • By the time onSettingsChange is called the new settings have already been merged with the old ones.  You'll likely see the same memory issue if you comment out onSettingsChanged.  And it's not that your main code is getting loaded and not just your glance code.  It's that when you change settings, it requires more memory for the "merge"

  • In my case the additional "merge" memory" doesn't seem to be the problem.
    I can see in debug log (Eclipse) that the apps onSettingsChanged() is called. There I create the API instance. And this call is crashing the app because the additional app code is loaded.

    As workaround I wondered if I can "see" somehow in onSettingsChanged that I'm inside the glande view and prevent calling the API. That's only necessary when the widgets main view is called.

  • Is the error because the the code you need isn't available in the glance?

    What you might try is setting a flag in getGlanceView and clearing it in getInitialView, and only do when you want based on that flag.

  • The code is:

    ...
    (:glance)
        function getGlanceView(){
            return [ new HomeyGlanceView() ];
        }

        function onSettingsChanged(){
            System.println("HomeyApp: onSettingsChanged");
            loadCategories();
            mColor = loadColor();
            mFont = loadFont();
            mHomeyLogo = getPropertyValue("HomeyLogo", true);
            WatchUi.requestUpdate();
        }
    ...

        function loadCategories(){
            System.println("HomeyApp: loadCategories");
            getHomeyApi();
    ...

    I wonder why onSettingsChanged() is called in glance view when it has not the (:glance) scope.
    I would expect that only the getGlanceView() is processed in glance mode.

    But independently I try to use a flag to remember the current scope. Thanks again for your help.

  • All of your AppBase is available in a glance view.  As if it had the (:glance) annotation.

  • Ah, didn't know that. I expected only signed parts are loaded in glance mode.