0

I am just making some tests and I created a simple immersion menu in a hello world activity. To do that, like it is said here, I had to implement the method onKeyDown:

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) {
        openOptionsMenu();
        return true;
    }
    return false;
}

The menu is shown properly but the problem is that now the one-finger-down gesture to just close the app doesn't work and for any reason I had to make a two-finger-down gesture to close it. Why is it happening?

Sca09
  • 361
  • 4
  • 13
  • Not sure, but maybe using a gesture detector instead of onKeyDown will work better? https://developers.google.com/glass/develop/gdk/input/touch – Zach Johnson Mar 11 '14 at 05:08
  • Well, I was just making some simple tests and I just followed the documentation on Google Developer site and it sounds weird for me that adding this I was disabling the basic one-finger-down action. Sure there is other ways to make it better but I just wanted to understand why it was happening – Sca09 Mar 11 '14 at 10:13

1 Answers1

0

Your problem is that you override the onKeyDown function.

You have two solution :

  • Handle yourself the KEYCODE_BACK like that :

    if(keyCode == KeyEvent.KEYCODE_BACK){ onBackPressed(); return true; }

  • return super.onKeyDown(keyCode, event); instead of return false;

Jean Vacca
  • 46
  • 2
  • To make it easier I just tested the second option and everything works as expected. Actually it makes sense once you explained, so very good answer. – Sca09 Mar 11 '14 at 20:46