Acknowledged

keyEvent.getKey() == 4 short vrs long pressed

Hi! I have the following problem, you might know the reason/solution.

I have the following code line:  if (keyEvent.getKey() == 4) {onSelect_lauch();}

I found that, in the simulator, for several devices, when I press the "Start-Stop buttom" (Key 4), if I press it long (not just one click but a "long" click), it launches properly the function but if I press it short, I gives me the typical error "Symbol Not found Error". It is an App (not a widget).

Error: Symbol Not Found Error

Details: Failed invoking <symbol>

Stack:

Do you know why and how to solve it?

Thanks!

Parents
  • Hi Flowstate. Are you sure it is needed to return false? It works on my Vivoactive4s. I do not see why false would be expected and "who" handles this false sent in return...

    The boolean return code indicates whether you handled a given key event or not. If you return true, the default handler will not run.

    Let's say you want to handle KEY_ESC in onKey(). You would want to return true whenever you handle KEY_ESC, otherwise the default handler would run (in most cases this would pop the current view.). Conversely, if you *don't* handle KEY_ESC in onKey(), you would want to return false in general, so the default handler runs.

    In your case:
    - There's no default handler for KEY_ENTER so it doesn't matter if you fail to return true when you handle it
    - If your function returns nothing, it's probably treated the same as if you returned false, so that covers other cases as well (e.g. KEY_ESC)

    However, the API specification does expect onKey() and other input handlers to return a boolean, for the reasons I mentioned above, so it's a good practice to write your code "properly" (to spec) in general, even if it doesn't make in a difference in certain cases. It just helps you write better code in general, IMO, and it also makes your code easier to understand.

Comment
  • Hi Flowstate. Are you sure it is needed to return false? It works on my Vivoactive4s. I do not see why false would be expected and "who" handles this false sent in return...

    The boolean return code indicates whether you handled a given key event or not. If you return true, the default handler will not run.

    Let's say you want to handle KEY_ESC in onKey(). You would want to return true whenever you handle KEY_ESC, otherwise the default handler would run (in most cases this would pop the current view.). Conversely, if you *don't* handle KEY_ESC in onKey(), you would want to return false in general, so the default handler runs.

    In your case:
    - There's no default handler for KEY_ENTER so it doesn't matter if you fail to return true when you handle it
    - If your function returns nothing, it's probably treated the same as if you returned false, so that covers other cases as well (e.g. KEY_ESC)

    However, the API specification does expect onKey() and other input handlers to return a boolean, for the reasons I mentioned above, so it's a good practice to write your code "properly" (to spec) in general, even if it doesn't make in a difference in certain cases. It just helps you write better code in general, IMO, and it also makes your code easier to understand.

Children