In android i have been able to override the funcationality of back button very easily but for my app i need to override the home button. I am sure it can be done but how can i achieve this.
Asked
Active
Viewed 114 times
-1
-
NO! you can not override android home key click event it prevented by system, only onStop method will call on home key click event. – Vijju Mar 10 '14 at 11:17
-
but when press home button i want to show an alert so how can i do this. – Harshit Rathi Mar 10 '14 at 11:19
-
on click of home key only onStop of activity will call, therefor displaying an alert on stop is not possible. – Vijju Mar 10 '14 at 11:23
1 Answers
0
Sorry to say but, It is not possible.Refer the link:-
http://developer.android.com/reference/android/view/KeyEvent.html#KEYCODE_HOME`
Key code constant: Home key. This key is handled by the framework and is never delivered to applications.
Many blogs suggest to use onPause() method of activity life cycle,for the same.But it takes a lot to manage.
I will suggest to use onUserLeaveHint() method.

Harshal Benake
- 2,391
- 1
- 23
- 40
-
but when light is off then onPause is called but i don't want to do this. – Harshit Rathi Mar 10 '14 at 11:27
-
ya i know. But most of the android blogs suggest to use onpause() methods. Its very difficult to manage.Can you tell what exactly you want to do on home press. – Harshal Benake Mar 10 '14 at 11:31
-
I want to display an alert when press home button and app is not gone in background. – Harshit Rathi Mar 10 '14 at 11:32
-