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 8928375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:25:29+00:00 2026-06-15T08:25:29+00:00

I know that I cant override the home button like with the back button.

  • 0

I know that I cant override the home button like with the back button. But can the android system fire an event if the home button is pressed? I want to catch this action in order to show a warning message if the user presses the home button. I’ve looked into several options, the most obvious one, for beginner would be to override the home button

public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_HOME) {
        // action goes here
    } else {
        return super.onKeyDown(keyCode, event);
    }
}

But this doesnt work, and I’m completly aware of it.

The onPause method will be called once the current Activity finishes. This method will also be called when the user changes Activity in my application. So is there anyway I can show the user a notifying box, when he presses the home button?

Thanks in advance

  • 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-15T08:25:30+00:00Added an answer on June 15, 2026 at 8:25 am

    Actually, it is not possible to catch home button pressed event like others, it is a feature to protect the user.

    But there is a hack for your situation:

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

    onAttachedToWindow

    This is called when the view is attached to a window

    You may read Activity Lifecycle how this hack works.

    Also, here is the evidence which shows this method works.

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

Sidebar

Related Questions

I know that can't use left join in indexed view. but I don't understand
I know that you can't have a constructor in an interface, but here is
I know that __stdcall functions can't have ellipses, but I want to be sure
i know that .NET String class uses such behaviour, but I can't find any
I know that we cant use assignment operator in if statements in java as
I know you cant do that with the Facebook API. Does OpenSocial allow me
I know that you can't repeat match groups in Lua. For example, if I
I know that we can't overload operator with other meaning, we can't create new
Before somebody points me to that question, I know that one can't parse html
Yes, I know that downcast using dynamic_cast can't compile if the Base is not

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.