Again Glance View problems

Hi,

I don't know what the reason is for following error message:

Error: Illegal Access (Out of Bounds)
Details: Failed invoking <symbol>
Stack:
- initialize() at C:\Users\Bernd\eclipse-workspace\Colors\source\colors.mc:89 0x100004c8
- initialize() at C:\Users\Bernd\eclipse-workspace\Colors\source\ColorsApp.mc:16 0x100000ce

I have defined in the main app a class called color:

    function initialize() {
        AppBase.initialize();
        cColor = new color();
    }

I tagged the class color with (:glance)

I initialized the values in the class color:

(:glance)
class color {
	hidden    var colors = new [64];

	function initialize() {
		colors[0]  = {:name => Rez.Strings.Black			, :oldName => Rez.Strings.Black		, :code => 	0		, :myColor => true	, :bright => false};
    ....
   }
}

I have zero problems with the very same watch in the simulator, if I deselct glance view causing to start with the initial view. Bus as soon as I tick glance in the simulator and recompile the error message is thrown. Can someone explain what's going on?

  • See "Resource Scopes" in the programmer's guide. Here's a bit from there:

    Adding resources to an app comes with a minor runtime memory cost. While the cost is small, it can seriously cut into the available memory for background services and glances. To mitigate these costs, Connect IQ 3.1 introduces an additional scope attribute to the following resource tags: <layout>, <drawable-list>, <bitmap>, <string>, <font>, <jsonData>. The scope attribute tells the resource compiler the type of application that the resource should be made available to. Valid values for the scope attribute are background, glance, and foreground. If the attribute is not specified for a resource, it will be considered part of the foreground scope by default. An example of using the scope attribute with string resources:

    <resources>
        <string id="MyBackgroundString" scope="background">Background String</string>
        <string id="MyGlanceString" scope="glance">Glance String</string>
        <string id="MyForegroundString" scope="foreground">Foreground String</string>
  • Hi Jim, thanks for that. I have adapted things and it works now. But glance view driving me nuts anyway. I have an old widget which isn't glance view compatibel. And this is what I mean that the concept of Garmin is not very consistent. Old widgets may not work without refactoring. Following problem:

    I defined in the base app:

        function onStart(state) {
            Position.enableLocationEvents(Position.LOCATION_CONTINUOUS, method(:onPosition));    
        }
    

    This works like a charm without glance. But with glance enabled, the watch throws an error message:

    Error: Permission Required
    Details: Permission for module 'Toybox.Position' required
    Stack:
    - onStart() at C:\Users\User\eclipse-workspace\Distance\source\DistanceApp.mc:17 0x10000ab2

    I have a similar command in the onStop() method... Any workaround for that?

  • NOt all things are available for glances views, and in this case, you can't enable gps.  What you want to do is move this to something like getInitialView().

  • And what about the onStop which contains the disabling of GPS 

  • You could use a boolean to see it's started before you disable it.

  • OK, I tried that: moved the onStart statement to the getInitialView, introduced a boolean which is initialized with false in the base app and set to true in getInitialView. 

    It works which means I don't see an IQ Error, but I get the very same error message as soon as I change from glance to initialview::


    Error: Permission Required
    Details: Permission for module 'Toybox.Position' required
    Stack:
    - onStop() at C:\Users\User\eclipse-workspace\Distance\source\DistanceApp.mc:22 0x10000adf

  • So something like this?

    class WyWid extends App.AppBase {
    
        var isFull=false;
        
        function initialize() {
            AppBase.initialize();
        }
    
        // onStart() is called on application start up
        function onStart(state) {
        }
    
        // onStop() is called when your application is exiting
        function onStop(state) {
            if(isFull) {
                //stop gps
            }
        }
    
        // Return the initial view of your application here
        function getInitialView() {
            isFull=true;
            //start gps
            return [ new MyView() ];
        }    
    
    }