How to read state in onStart

Hi, I can't figure out how to read 'state' in the onStart function. All options I tried to retrieved  launchedFromGlance from it failed. All I can retrieve is its symbol (8391789). Doing a "toString" on that symbol do not convert it to launchedFromGlance but makes the symbol number a string  From what I read, symbol numbers can't be assumed to be constant across build so I'm at lost on how to retrieve it. There is nothing in the samples and a Google search yielded nothing :-(

Thanks,

  • As you said correctly symbol numbers are not constants.

    If I am stuck on a function, best address is most often the API documentation:

    https://developer.garmin.com/connect-iq/api-docs/Toybox/Application/AppBase.html#onStart-instance_function

    There you see how the symbols are named.

    Try this:

    function onStart(state as Dictionary?) as Void {
            System.println("App onStart");
            if (state != null) {
                System.println("full state: " + state.toString());
                System.println("resume: " + state.get(:resume ));
                System.println("launchedFromGlance: " + state.get(:launchedFromGlance));
                System.println("launchedFromComplication: " + state.get(:launchedFromComplication ));
            }
        }

    As the documentation writes. state is a dictionary with the keys :resume, :launchedFromGlance and :launchedFromComplication. Use the method get from a Dictionary to retrieve its values.

    It is important to check if the state is null or not. If I start the app without a GlanceView in the simulator, the state is null. So you can conclude that if the state is null, it is not launched from glance.

  • Where did you get that doc? This is all I get when I click on the link you provided (which is where I went last night too), hence why this post since it didn't make sense.

  • The doc in the link and screenshot says what Remoh wrote above (that state is a dictionary with keys :resume, :launchedFromGlance and :launchedFromComplication), it's just that the example in the docs could be better (to say the least.)

    The idea is that Symbols are supposed to be opaque identifiers (meaning you're not supposed to care about the underlying value), so you don't really want to try to convert them to anything else (such as a string) except possibly for debugging purposes.