1

Hi I have written the following code:

public boolean onKeyDown(int keyCode,KeyEvent event) {
    if (keyCode==KeyEvent.KEYCODE_HOME) {
        showDialog(MY_DALOG);
        return  true;
    }
    return true;
}

But when I press the HOME BUTTON, it doesn't call the line if(keyCode==KeyEvent.KEYCODE_HOME) when debugging.

On the other hand, it calls the onPause(). I have put my code in onPause() but still, it shows a SuperNotFound exception in Logcat.

Any idea how to display a dialog by pressing the HOMEKEY?

4 Answers4

3

The Home Button will be handled by the PhoneWindowManager in the Android framework. It will be sent to the Launcher application. No other application will receive it in their Activity.

RvdK
  • 19,580
  • 4
  • 64
  • 107
2

KeyEvent.KEYCODE_HOME is not for the developers. Android has made it safe for themselves. So that no application would force the user to stay inside their application.

Chandra Sekhar
  • 18,914
  • 16
  • 84
  • 125
  • but i have seen some application where they are displaying alertdialogs by pressing home button –  May 02 '13 at 10:24
  • 1
    @user2295109 Can u please mention on which application you have seen that behaviour? – Chandra Sekhar May 02 '13 at 10:26
  • i dont think its necessary. –  May 02 '13 at 10:29
  • @user2295109 Well I don't know in which application you have seen that. But ideally it shouldn't happen as its not allowed in Android. For more info please check http://stackoverflow.com/questions/2079691/overriding-the-home-button-how-do-i-get-rid-of-the-choice – Chandra Sekhar May 02 '13 at 10:36
  • @chandra Sekhar there should be some hack around i ave also seen many application they have this functionality. – Abhijit Chakra May 02 '13 at 10:44
  • @rickky Yes you are right. But do you think its really feasible for a developer to implement this? – Chandra Sekhar May 02 '13 at 10:48
  • 1
    It is not something that is allowed, so a hack is necessary. That's an extremely bad idea though imho. It is forbidden for a reason, if an user wants to go back to home, there is no legitimate reason to force him to stay in your app. – Teovald May 02 '13 at 10:51
  • may be the developers intention is if the user accidentally pressed then home button it will show a warning for that may be for this he needs a dialog. – Abhijit Chakra May 02 '13 at 10:55
0

Sorry. you can show alert dialogue by pressing back button of device.

But, you can't implement those feature with HOME Button pressed. Because, Android is designed as automatically launch home page without consider about anything happening right now on UI, While pressing it.

Dhasneem
  • 4,037
  • 4
  • 33
  • 47
0

This is actually possible. But you have to make your own 'home screen replacement' app, and let the user set your app as the user's new home screen. But this is probably a much more complicated solution than what you are looking for...

DKIT
  • 3,471
  • 2
  • 20
  • 24