Menu2 displays on emulator but doesn't on real device

I'm trying to develop my first application for my Garmin watch, I'm getting by as best I can, but I'm currently having a problem.

I want to take the user through a menu to activate/deactivate options. This works perfectly on the emulator/simulator (Garmin 7 Pro) but doesn't work at all on the real watch...

Here's the line of code I commented out: codeberg.org/.../InstructionDelegate.mc

Thanks for your help.

  • I tried out your app (thanks for providing the source) after restoring the code you commented out, and saw that on a real device, the Options menu is empty (only the title is displayed), as I would've guessed. My hunch was that onLayout() is not called for MenuView (which extends Menu2), which means that addItem() is never called.

    Indeed, if you move all the code (which includes all the addItem() calls) from onLayout() to initialize(), it works as expected.

    Just another case where the sim doesn't act like a real device. The docs say that onLayout() is the "entry point" for a view, but they also show onLayout() as part of the app lifecycle where it's implied that it's called for the top-level view (but nothing is said about other views pushed by the app.) My 2 cents is I wouldn't rely on onLayout() being called for anything other than a top-level view.

    Also, it wasn't possible for me to (gracefully) exit your app on a real device (955). I was only able to do so via a hotkey I've assigned to return to the watch face. You might want to look into the onBack() function in InstructionDelegate. If all you want to do is pop the current view when the user presses Back, you can simply do nothing (and return false) in onBack(), or even better, do not override onBack(). (Having said that, I'm not sure why your current code doesn't seem to work, as it is trying to pop the current view.)

  • Thanks a lot for your reply! I'll have a look and give some feedback Slight smile

  • Sure np!

    Fixed the fact that it is not possible to exit the app with this: https://codeberg.org/retiolus/garmin-luc-leger/src/tag/v0.1.2/source/InstructionDelegate.mc#L27

    Oh right, the reason onBack() was not called when LAP/BACK was pressed is because onKey() returns true in all cases (meaning that the default system action is suppressed for any key that a CIQ app is able to handle). (However, onBack() would be triggered when the user swipes right, which is something I forgot to try.)

    So rn you have a lot of unnecessary code.

    I think the cleanest way to handle this would be:

    - remove onBack() completely

    - in onKey(), get rid of the code that handles KEY_ESC

    - in onKey(), only return true when you actually handle a key (KEY_UP/DOWN/ENTER). In all other cases, return false

    That way the system will take the default action when LAP/BACK is pressed or the user swipes right on the top-level view: the view will be popped and the app will close.