I'm experiencing some issues when trying to handle a menu in my app. First of all, I've about 1 week experience in Monkey-C and know nothing about any other object-oriented programming language (I'm not a programmer), so I apologize for any stupid question I might state.
Here is the situation: I'm building an app that starts showing a menu (subclass of WatchUi.Menu) so the user may perform some configurations prior to run the main view. After the user makes the selection, the menu pops out and the main view is brought to the foreground. This menu is already working but I realized that the user could press the back button without making any selection which is an undesirable situation for me. In this last situation I would like to terminate the app.
Now, the issue is that I cannot find any way to terminate the app in a "clean" way. I'll try to explain why I cannot:
1. First of all, I cannot use the menu as the initial view (I got a "Socket Error in packet header 0" error). Therefore, my initial view is the main view (subclass of WatchUi.View). To show the menu before the main view, I pushView'ed the menu at the initialization of the main view.
2. I decided to set the menu selection as null until the user makes the selection. At the main view onShow() method I check whether this selection is null or not, and terminate the app if it's null. However, as long as the main view is the initial view, his onShow() method is called even after pushView'ing the menu (not only after popping out the menu). Since the selection is initialized as null, the app will terminate without letting the user to make any selection. (note: the onUpdate() method in main view is also called at the initialization).
3. I also tried capturing the back button press at my WatchUi.MenuInputDelegate subclass, but no handleEvent(), onKey() or onBack() methods are called when pressing that button. So it made no difference.
4. I was thinking about using a method that lets me see the order of the view stack, so I can check whether the menu or the main view are on the foreground. That way I can use the strategy in "2.", because if onShow() is called in the main view when it is not on the foreground I can avoid checking if the selection is null. However, I think this method does not exist.
Finally, the only solution I find is to define a flag variable that triggers after onShow() in main view is called for the first time, so I can avoid checking the selection in the first call (before the menu is displayed). However I think this is a "dirty" way of doing it, and I'll bet I'm misunderstanding the WatchUi.Menu functionality.
Just to add some more information on this, I placed a System.println() at the begining of all methods in the main view and in the menu, so here is the sequence of calls in my app:
-> App starts
MenuDelegate - initialize()
MainView - initialize()
MenuView - initialize()
MenuView is pushView'ed
MainView - onShow()
MainView - onUpdate()
MainView - onHide()
-> User presses back button
MainView - onShow()
MainView - onUpdate()
-> User presses back button again
MainView - onHide()
-> App terminates
Thanks in advance for your kind help!