tags:

views:

198

answers:

2

Hi,

Can you please tell me how can my activity detect user pressing HOME key?

Thank you.

A: 
android.text.method.KeyListener.onKeyDown([view],[text],KEYCODE_HOME,[event])

I'm not sure how the other parameters fit in, or even how to implement the above, but the info is all at the keylistner documentation.

But they also mention at another page that the home key ALWAYS goes home, you can't change that. So if you plan on having some kind of "are you sure you want to quit" dialog, that wouldn't work.

Anthony
+2  A: 

You can't capture the HOME event and intercept it in any way. The user will always be taken to the home screen of their device when they press the home key.

If you need to know when your Activity is being sent to the background, like from the user pressing the home or back keys, I'd implement the onStop() method.

mbaird