Click the menu key.

Source: Internet
Author: User

In the project, a listener method is added to the menu key on the logon interface. When triggered, the IP address is configured, which is useful in the early stage.

At the end of the recent project, I started the test and found that the menu key was invalid. I monitored the code. That's right. debug found that the listening time was not happening, and I felt like a ghost.

I keep thinking, and finally found that I re-wrote the onkeydown (INT keycode, keyevent event) method, but it feels correct, because I listened to the returned key

The returned value is true. When I carefully looked at the API, I found that the menu key was invalid because of the true value I returned:

 boolean com.jh.jhcs.activity.LoginActivity.onKeyDown(int keyCode, KeyEvent event)@OverrideCalled when a key was pressed down and not handled by any of the views inside of the activity. So, for example, key presses while the cursor is inside a TextView will not trigger the event (unless it is a navigation to another object) because TextView handles its own key presses. If the focused view didn't want this event, this method is called. The default implementation takes care of KeyEvent.KEYCODE_BACK by calling onBackPressed(), though the behavior varies based on the application compatibility mode: for android.os.Build.VERSION_CODES.ECLAIR or later applications, it will set up the dispatch to call onKeyUp where the action will be performed; for earlier applications, it will perform the action immediately in on-down, as those versions of the platform behaved. Other additional default key handling may be performed if configured with setDefaultKeyMode.Overrides: onKeyDown(...) in ActivityParameters:keyCode The value in event.getKeyCode().event Description of the key event.Returns:Return true to prevent this event from being propagated further, or false to indicate that you have not handled this event and it should continue to be propagated.

The returned description is as follows:

Return true to prevent this event from being propagated further, or false to indicate that you have not handled this event and it should continue to be propagated.
 
It means that when you return true, when you reach the listening key, it will interrupt the event propagation and will not find the matching result. When you return false, when you reach the listening key, he will continue to check all the key events of the system: do not know
 // key codes    public static final int KEYCODE_UNKNOWN         = 0;    public static final int KEYCODE_SOFT_LEFT       = 1;    public static final int KEYCODE_SOFT_RIGHT      = 2;    public static final int KEYCODE_HOME            = 3;    public static final int KEYCODE_BACK            = 4;    public static final int KEYCODE_CALL            = 5;    public static final int KEYCODE_ENDCALL         = 6;    public static final int KEYCODE_0               = 7;    public static final int KEYCODE_1               = 8;    public static final int KEYCODE_2               = 9;    public static final int KEYCODE_3               = 10;    public static final int KEYCODE_4               = 11;    public static final int KEYCODE_5               = 12;    public static final int KEYCODE_6               = 13;    public static final int KEYCODE_7               = 14;    public static final int KEYCODE_8               = 15;    public static final int KEYCODE_9               = 16;    public static final int KEYCODE_STAR            = 17;    public static final int KEYCODE_POUND           = 18;    public static final int KEYCODE_DPAD_UP         = 19;    public static final int KEYCODE_DPAD_DOWN       = 20;    public static final int KEYCODE_DPAD_LEFT       = 21;    public static final int KEYCODE_DPAD_RIGHT      = 22;    public static final int KEYCODE_DPAD_CENTER     = 23;    public static final int KEYCODE_VOLUME_UP       = 24;    public static final int KEYCODE_VOLUME_DOWN     = 25;    public static final int KEYCODE_POWER           = 26;    public static final int KEYCODE_CAMERA          = 27;    public static final int KEYCODE_CLEAR           = 28;    public static final int KEYCODE_A               = 29;    public static final int KEYCODE_B               = 30;    public static final int KEYCODE_C               = 31;    public static final int KEYCODE_D               = 32;    public static final int KEYCODE_E               = 33;    public static final int KEYCODE_F               = 34;    public static final int KEYCODE_G               = 35;    public static final int KEYCODE_H               = 36;    public static final int KEYCODE_I               = 37;    public static final int KEYCODE_J               = 38;    public static final int KEYCODE_K               = 39;    public static final int KEYCODE_L               = 40;    public static final int KEYCODE_M               = 41;    public static final int KEYCODE_N               = 42;    public static final int KEYCODE_O               = 43;    public static final int KEYCODE_P               = 44;    public static final int KEYCODE_Q               = 45;    public static final int KEYCODE_R               = 46;    public static final int KEYCODE_S               = 47;    public static final int KEYCODE_T               = 48;    public static final int KEYCODE_U               = 49;    public static final int KEYCODE_V               = 50;    public static final int KEYCODE_W               = 51;    public static final int KEYCODE_X               = 52;    public static final int KEYCODE_Y               = 53;    public static final int KEYCODE_Z               = 54;    public static final int KEYCODE_COMMA           = 55;    public static final int KEYCODE_PERIOD          = 56;    public static final int KEYCODE_ALT_LEFT        = 57;    public static final int KEYCODE_ALT_RIGHT       = 58;    public static final int KEYCODE_SHIFT_LEFT      = 59;    public static final int KEYCODE_SHIFT_RIGHT     = 60;    public static final int KEYCODE_TAB             = 61;    public static final int KEYCODE_SPACE           = 62;    public static final int KEYCODE_SYM             = 63;    public static final int KEYCODE_EXPLORER        = 64;    public static final int KEYCODE_ENVELOPE        = 65;    public static final int KEYCODE_ENTER           = 66;    public static final int KEYCODE_DEL             = 67;    public static final int KEYCODE_GRAVE           = 68;    public static final int KEYCODE_MINUS           = 69;    public static final int KEYCODE_EQUALS          = 70;    public static final int KEYCODE_LEFT_BRACKET    = 71;    public static final int KEYCODE_RIGHT_BRACKET   = 72;    public static final int KEYCODE_BACKSLASH       = 73;    public static final int KEYCODE_SEMICOLON       = 74;    public static final int KEYCODE_APOSTROPHE      = 75;    public static final int KEYCODE_SLASH           = 76;    public static final int KEYCODE_AT              = 77;    public static final int KEYCODE_NUM             = 78;    public static final int KEYCODE_HEADSETHOOK     = 79;    public static final int KEYCODE_FOCUS           = 80;   // *Camera* focus    public static final int KEYCODE_PLUS            = 81;    public static final int KEYCODE_MENU            = 82;    public static final int KEYCODE_NOTIFICATION    = 83;    public static final int KEYCODE_SEARCH          = 84;    public static final int KEYCODE_MEDIA_PLAY_PAUSE= 85;    public static final int KEYCODE_MEDIA_STOP      = 86;    public static final int KEYCODE_MEDIA_NEXT      = 87;    public static final int KEYCODE_MEDIA_PREVIOUS  = 88;    public static final int KEYCODE_MEDIA_REWIND    = 89;    public static final int KEYCODE_MEDIA_FAST_FORWARD = 90;    public static final int KEYCODE_MUTE            = 91;    public static final int KEYCODE_PAGE_UP         = 92;    public static final int KEYCODE_PAGE_DOWN       = 93;    public static final int KEYCODE_PICTSYMBOLS     = 94;   // switch symbol-sets (Emoji,Kao-moji)    public static final int KEYCODE_SWITCH_CHARSET  = 95;   // switch char-sets (Kanji,Katakana)

After reading the keyevent source code, my back key value is 4 and the menu key value is 84. Therefore, if true is returned, my menu key listening cannot be triggered.

over

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.