Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6576975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:34:40+00:00 2026-05-25T15:34:40+00:00

I am developing an Android app. I have written my own code for back

  • 0

I am developing an Android app. I have written my own code for back key event.
For that i am catching events using this method
public boolean onKeyDown(int keyCode, KeyEvent event) …..

I also want to use Menu options I have used Inflator for that.
But when I click on menu button, that event caught by my onKeyDown method.

I am not expecting that, I expect to execute following methods,

public boolean onCreateOptionsMenu(Menu menu){ // creating menu using MenuInflator }

public boolean onOptionsItemSelected(MenuItem item) {
        // Handle item selection
        switch (item.getItemId()) {
        case :
            return true;
        default:

        }
    }

How could I use both the things on the same activity?? Any Idea ???

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T15:34:41+00:00Added an answer on May 25, 2026 at 3:34 pm

    According to the documentation of onKeyDown():

    • it is normal that it receives the ‘menu button pressed’ event, as any KeyEvent

    • but if you return false, this event will continue to be propagated and will therefore lead onOptionsItemSelected() to be called

    So you should code your onKeyDown() in a way that lets the KeyEvent to propagate if you do not handle it on your own.

    In the following example, we have two keys that are interesting to us: one we fully handle on our own, one we just track, and we ignore all the rest:

    protected boolean onKeyDown(int keyCode, KeyEvent event) {
        boolean handled = false; // By default we let the event propagation turned on
    
        if (keyCode == A_KEY_YOU_WOULD_LIKE_TO_HANDLE_BY_YOURSELF) {
            doSomething();
            handled = true; // Stops the event propagation
        }
        else if (keyCode == A_KEY_YOU_WOULD_LIKE_TO_TRACK_WITHOUT_PREVENTING_THE_SYSTEM_FROM_HANDLING_IT) {
            doSomethingElse();
        }
        // else, you neither handle or track that key
    
        return handled;
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have basically finished developing an android app that makes use of SQLite databases
I have project where i'm developing an Android App using a lot of existing
I'm developing a Android App. This App have an SQLite Database. This Database have
hi guys i have been developing android app that should match most of the
I am developing an Android app (see screenshots). I have a layout that looks
I'm currently developing an Android application that fetches images using http requests. It would
I have been developing an Android app and testing with a 1.5 AVD and
I am developing an Android App and would like to have a video file
I am developing an Android app that needs to receive specific informations for each
In my Android app, I have some data that needs to be synced daily

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.