0

How can I start a progress dialog when the default Home Key button of Android is pressed? If it's possible, then how?

I've tried using the onKeyDown method, but it doesn't work.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Sanat Pandey
  • 4,081
  • 17
  • 75
  • 132

4 Answers4

0

Not really, no. You cant override the home button as you would the back or search.Take a look at this discussion:

Overriding the Home button - how do I get rid of the choice?

Community
  • 1
  • 1
Sam Dozor
  • 40,335
  • 6
  • 42
  • 42
0

Duplicates this: Android - capture/suppress Home and EndCall buttons events?

The short answer: you can not handle Home button, but you can write a replacement Home Screen application.

Community
  • 1
  • 1
praetorian droid
  • 2,989
  • 1
  • 17
  • 19
0

Because the 'Home' button is such an essential feature to android (It provides the user with a quick one-touch button to get back to their home screen) that they made it so we can't run custom code to modify what it does. We do however, somewhat have control over what happens when the user presses the menu, back, or search buttons.

It's always best to conform to Android's UI design guidelines, this article on application design is a great read on how exactly we should go about things.

Hammy
  • 109
  • 1
  • 9
0

The prevailing wisdom says it cannot be done.

Checkout this conversation:

Home key press Event Listener

Maybe the below code would work the way you want it to. But I don't think you can trap the Home key absolutely.

Override below method in your activity.

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

Then after you can listen home key in your activity.

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {     

        if(keyCode == KeyEvent.KEYCODE_HOME)
        {}
    });

Hope this may helpful to you.

Community
  • 1
  • 1
nisha.113a5
  • 2,024
  • 16
  • 30