Widget Second Screen

Former Member
Former Member
For my widget I am trying to develop a second screen.

I have added a new view using a listener on the enter event:

function onKey(evt) {
if (evt.getKey() == Ui.KEY_ENTER) {
Ui.pushView(new CView(), new CDelegate(), Ui.SLIDE_DOWN);
return true;
}

return false;
}


I then want to enable returning back to the main view:

class CDelegate extends Ui.BehaviorDelegate {
function onBack() {
switchBack();
System.println("BACK");
return true;
}

function onNextPage() {
System.println("NEXT PAGE");
switchBack();
return true;
}

function onPreviousPage() {
System.println("PREVIOUS PAGE");
switchBack();
return true;
}

function switchBack() {
Ui.popView(Ui.SWIPE_DOWN);
}}


This works fine on the simulator. However when testing on my watch when returning from the second view the watch displays the normal watch face for a few seconds and then goes back to the main page of my widget. However the functionality is strange. For example it doesn't really respond to more keys except after a long delay. It's as almost as if the event is being captured first by the watch and then by the widget and something goes wrong. A similar thing happens with up or down. It momentarily returns to the main page of the widget and then goes to the next real widget - again as if the watch has captured the event.

When I look at the CIQ_LOG.txt log I get the following message:

TVM ERROR:
Circular Dependency Error
Unfreed memory on exit


I know that something like this must be possible because the widgets such as the Weather or barometer widget use the "enter" key and return functionality.

What I am doing wrong?
  • sorry. I can't offer any solution.
    I am however following this thread as I too get the same CIQ Error Log message.
  • Former Member
    Former Member over 10 years ago
    After testing this has to be a bug on the watch.

    I have added the simplest of views that just displays some text.

    The same thing happens. I would love to know how the "native" widgets deal with this.

    Can anyone from Garmin shed some light on this?
  • Former Member
    Former Member over 10 years ago
    This is now happening from an app I am developing. New view, go back - jumps to the app menu with the same error as above written in the logs.

    I would love someone from ConnectIQ to shed light on this.
  • Former Member
    Former Member over 10 years ago
    I'm not sure what could be going on here. Are there any other errors in the log? It sounds like there may be a device bug, but it is hard to say for sure.

    If you can post a full example that replicates the behavior, or send your project to [email][email protected][/email], I can investigate directly.
  • Former Member
    Former Member over 10 years ago
    I've identified a device level VM issue that is causing the onBack behavior to trigger when the new keyPressed() event occurs when it should not. This causes the example provided by slipperybee to pop its own view in that event. The default behavior that pops a page automatically is then triggered when the normal onBack event occurs and is not processed.

    At this time you can work around this issue by replacing handling onBack() with handling onKey(). This would be done by replacing this code:
    function onBack() {
    Ui.popView(Ui.SLIDE_UP);
    return true;
    }

    with this code:
    function onKey(evt) {
    if(evt.getKey() == Toybox.WatchUi.KEY_ESC) {
    Ui.popView(Ui.SLIDE_UP);
    return true;
    }
    }
  • I've identified a device level VM issue that is causing the onBack behavior to trigger when the new keyPressed() event occurs when it should not. This causes the example provided by slipperybee to pop its own view in that event. The default behavior that pops a page automatically is then triggered when the normal onBack event occurs and is not processed.

    At this time you can work around this issue by replacing handling onBack() with handling onKey(). This would be done by replacing this code:
    function onBack() {
    Ui.popView(Ui.SLIDE_UP);
    return true;
    }

    with this code:
    function onKey(evt) {
    if(evt.getKey() == Toybox.WatchUi.KEY_ESC) {
    Ui.popView(Ui.SLIDE_UP);
    return true;
    }
    }

    What about the circular dependency error and unfreed memory? I am not doing the switch back but using the esd key and get the messages in CIQ_LOG
  • Depending on your code, there is a different way to handle multiple pages, as seen in the the "userprofile" sample in the SDK

    in the input delegate, it sets the page number in a global, and then in "onUpdate()" it paints the correct data on the screen for that page. It uses dc calls and not layouts. and no push/pop views.

    It's the way I've done a few things with multiple pages, and it makes things a bit easier if some of the same data is used on multiple pages
  • If you do this then you won't get page transitions.
  • If you do this then you won't get page transitions.


    Why does that concern me? A new page is picked in the delagate, and I just call Ui.RequestUpdate()! Works great.... And faster (less expensive CPU wise) than pushing and popping! It may depend on your specific app as far as the best approach.
  • I'm simply telling the users about the downside of using this technique. You may not care about the loss of page transitions, but they may.