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

  • SEARCH
  • Home
  • 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 7929637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T20:08:57+00:00 2026-06-03T20:08:57+00:00

I override the home button like this : @Override public boolean onKeyDown(int keyCode, KeyEvent

  • 0

I override the home button like this :

@Override 
public boolean onKeyDown(int keyCode, KeyEvent event) {
    switch (keyCode) {
    case KeyEvent.KEYCODE_HOME: 
        System.out.println("hello");
        break;
    }
    return super.onKeyDown(keyCode, event);
}


@Override
public void onAttachedToWindow() {
    this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
    super.onAttachedToWindow();
}

I create also a search interface like :
http://www.edumobile.org/android/android-programming-tutorials/search-interface/

When I click on the search hardware button, the search interface comes up. But at the same time when I click on the home button, the overridden method for Home button is not called, and I go back to main screen of phone. Can you help me how can I fix it?

  • 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-06-03T20:08:59+00:00Added an answer on June 3, 2026 at 8:08 pm

    You can not catch the Home-Button presses, see this question on SO for further details. In short: It is a system key, your application can not handle it on its own because it would allow a application to prevent the user from exiting it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

protected override Boolean IsValid(String propertyValue) { return !String.IsNullOrEmpty(propertyValue) && propertyValue.Trim().Length > 0; } This
I use the following: @Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
This is my .java code public class MainHelp extends PreferenceActivity { @Override public void
Possible Duplicate: Can i override HOME Button on my own Home-Screen from my application?
I am using category android:name=android.intent.category.HOME category android:name=android.intent.category.DEFAULT to override the HOME button behavior and
I was wondering if I can override the action of the back and home
@Override public void onCreate(SQLiteDatabase db) { db.execSQL(DATABASE_CREATE); // providers data // db.execSQL(insert into //
@Override public void onCancel() { // TODO Auto-generated method stub ERROR:The method onCancel() of
I'd like to override the Serialize methods of the ASP.NET JavaScriptSerializer class. Nothing too
On pressing the back button, I'd like my application to go into the stopped

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.