Here's some simple code that show you two options (controlled by useDelegate). If false, it's similar to what you are doing, but instead of trying to do the pop, it puts up a screen. That screen…
In my case, I had to push a second view (maps), but in most of my widgets, I just use a single view, with a "page number" to display different data. Single view, no problem.
At the Oct Conference…
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();
}
}
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.
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.