Starting an app in a menu

Former Member
Former Member
Playing around in the menu test sample. I want to be able to go from choosing an app straight into showing the top level menu. The menu test app shows a splash screen and only when the user presses the menu button does the menu get displayed.

I have tried several modifications but none of them work.

1.
Change the apps getInitialView from:

function getInitialView() {
return [ new MenuTestView(), new MenuTestDelegate() ];
}

to :

function getInitialView() {
return [new Rez.Menus.MainMenu(), new MenuTestMenuDelegate() ];
}

on the assumption that Ui.pushView can take either new MenuTestView() or new Rez.Menus.MainMenu() so the getInitialView should probably do the same. This change compiles OK but exits immediately in the simulator.

2.
Added onShow() to MenuTestView class

function onShow() {
Ui.switchToView(new Rez.Menus.MainMenu(), new MenuTestMenuDelegate(), Ui.SLIDE_UP);
}

but the simulator gives:
Failed invoking <symbol>
Symbol Not Found Error

error on startup. Not very helpful.

3.

Added onShow() to MenuTestView class

function onShow() {
Ui.pushView(new Rez.Menus.MainMenu(), new MenuTestMenuDelegate(), Ui.SLIDE_UP);
}

and adding to MenuTestDelegate

function onBack() {
Ui.popView(Ui.SLIDE_DOWN);
}

shows the menu immediately but pushing the back button to exit the app does nothing.



How do I start an app by showing a menu and then exit the app immediately by hitting the back button? I obviously want to do more than this (and I have successfully), but getting this seemingly trivial behaviour is defeating me. The docs don't make it clear the relationship between a view and a menu. On a watch where the menu takes over the whole screen it seams like it is just a specialised view.

Dave.
  • Former Member
    Former Member over 8 years ago
    Your base view cannot be a native view, and you cannot use switchToView with native views, so 1 and 2 are not allowed.

    You should be able to accomplish the effect you are going for by using a helper view as your base view. What you outline in your 3rd option should work. Your base view will need to push the menu as you have done, but it will also need to handle the responses from the menu and pop itself in the case where the menu is exited without selecting an item. The code you have described would pop the menu, and return to the base view, which would then run onShow and immediately re-push the menu. You will need more complex logic to determine what conditions are causing you to reach the base page.
  • The system was designed to expect that the initial view (or the top-most view) is derived from Ui.View. I think it probably violates the UX guidelines, but you should be able to hack around this if you really want. You just need to automatically push the menu when showing the initial view, and then automatically pop the view when the menu is dismissed.

    class StartView extends Ui.View
    {
    hidden var firstShow;

    function initialize() {
    View.initialize();
    firstShow = true;
    }

    function onShow() {

    // if this is the first call to `onShow', then we want the menu to immediately appear
    if (firstShow) {
    Ui.pushView(new Rez.Menus.MainMenu(), new MenuTestMenuDelegate(), Ui.SLIDE_IMMEDIATE);
    firstShow = false;
    }

    // otherwise, we are returning to this view, most likely be cause the menu was exited,
    // either by pressing back, or by selecting an item that caused the menu to be popped,
    // so we want to pop ourselves
    else {
    Ui.popView(Ui.SLIDE_IMMEDIATE);
    }
    }
    }

    class StartDelegate extends Ui.BehaviorDelegate
    {
    function initialize() {
    BehaviorDelegate.initialize();
    }
    }


    Travis
  • Former Member
    Former Member over 8 years ago
    Thank you so much - that worked perfectly.

    Dave.
  • Hi Travis,

    your code works flawlessly but i have problem with widget exit and doesn't matter if your watch have a glances or not. If use pop to "exit menu" i get this message:

    Error: Unhandled Exception

    Exception: Base view is not allowed to pop for widgets

    Stack: 

      - popView() at /private/var/jenkins/workspace/Tech-Rel-CIQ-Mac/mbsimulator/submodules/technology/monkeybrains/virtual-machine/api/WatchUi.mb:3800 0x30003e6a 

      - onShow() at /Users/mara/Downloads/_garmin/kuki/source/KukiWatchView.mc:57 0x10003765 

    Do you have any idea please ? I try everythink without any success :-) 

    Thanks a lot

  • You can not programmatically exit a widget.  popView(), System.exit() aren't allowed.  You need to be at a point where you're on the main view and the back key is pressed.

    The error message you see is correct.  Doing the pop view of the main view isn't allowed.  What I do is I have an extra screen at the end telling the user to press back.  Here's an example.  When the widget starts, it's trying to get a GPS loc.  Once it does, it pushes a MapView.  When the user backs out of the map, I have another screen to exit.

  • YES you are true but i'am using Menu2 like in example directly without screen "press menu button to open the menu". In this scenario after back button see only black screen because you cant use  popView(), System.exit(), etc.

  • If you have a Menu2 as your top view, what happens if you press back, with no pushView ,popView(),or System.exit calls? and nothing in an onBack() callback?

  • code is same like in example - just one Ui.pushView to initialize Menu2 with "firstShow" hack by Travis. If you push back directly in Menu2, onShow calls again. Than skip first "if (firstShow)" because now is false and go straight to "else" where is pop. If i remove pop (because we know it's not on the right place), menu disappears to a black screen and waiting to another beck press and after than widget quit. Problem is in the second press, i dont know how to solve it.

  • The example is for a device app, and you're doing a widget.  Widgets work differently. You can't do the pop like you can in a device app.

  • YES as device-app pop works, but i need a widget. I will probably have to write my own menu :-(