tags:

views:

56

answers:

2

If the user taps the Home key, I can pause my application because the onPause event fires.

However, if the user long-presses Home, the recent app launcher pops up and my application carries on running behind it.

I want to pause my application in this situation. What can I do?

(NB. I don't want to prevent the long-press of Home or alter its behaviour in any way. My app just needs to know it's happened. It's a game, so I want to pause it.)

A: 

You could override the onKeyLongPress() method in your activity, do what you want, and then just call the super method.

http://android-developers.blogspot.com/2009/12/back-and-other-hard-keys-three-stories.html

softarn
Unfortunately this event doesn't fire for a long press of the Home key (though it does for other keys: Search works, for example).
teedyay
+1  A: 

If all else fails, give the user the ability to manually pause (via button or menu).

It sounds like you've got a situation where the user would be unhappy with your game continuing during the long-press, but at this point the user has already shifted focus away from the game. If I were in the midst of a time-sensitive game and wanted to navigate away by long-pressing the Home button, my first thought would be to manually pause the game.

Just food for thought, good luck.

Josh