This question already has an answer here:
- Detect home button press in android 14 answers
Can you please tell me how can my activity detect user pressing HOME key?
Thank you.
This question already has an answer here:
Can you please tell me how can my activity detect user pressing HOME key?
Thank you.
It can be done(uptil 2.3 atleast). Tested on android version 2.3.5 non-rooted HTC WildFire-S. Code snippet to catch/disable all the control keys :
You can detect a HOME button press via Activity.onUserLeaveHint(). This method is called in two situations; when the user presses HOME and when a new activity is started. Make sure to somehow differenciate between the two.
use onUserLeaveHint() method in your Activity
http://developer.android.com/reference/android/app/Activity.html#onUserLeaveHint()
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.
You can write a Broadcast listener and set the filter to
From the Broadcast receiver start ur activity/ notify the activity.