• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Intercept HOME button click

 
yash wardhan
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi All,

Can we intercept HOME button click on android device or emulator.
If no, then which are the methods called before home screen is displayed on pressing HOME key?
I checked by overriding the life cycle methods of activity, it shows onPause() and onStop() are called but they are called even when we switch between the activities?
Any suggestions are appreciated

Regards,
 
Monu Tripathi
Rancher
Posts: 1369
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think you can intercept HOME key presses. It is reserved to ensure that you dont get locked within any application.

You can test this by coding a simple activity and overriding the onKeyDown(..) method. If you run this application and press the home button you will notice that the onKeyDown(..) callback in your code will NOT be invoked. Also, note that your onKeyDown(..) callback will be called only when(this comes straight from API docs) -
Called when a key was pressed down and not handled by any of the views inside of the activity. So, for example, key presses while the cursor is inside a TextView will not trigger the event (unless it is a navigation to another object) because TextView handles its own key presses...

So, I think that proves that you cannot intercept HOME key via onKeyDown(..) atleast. If there are any other means or if you meant something else then I dont know the answer.

As regards your second question -

Pressing the HOME button starts the launcher activity so yes, you are essentially, switching activites.
The intent fired has following properties/attributes(see DDMS->logcat for details):


CallBacks invoked when you press HOME button(listed in order) :
  • onSaveInstanceState(Bundle outState)
  • onPause()
  • onStop()

  • * Note that your activity will not be destroyed.

    Hope that helps...
     
    p blundell
    Greenhorn
    Posts: 1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Monu Tripathi wrote:I don't think you can intercept HOME key presses.



    Just a question, so if this Intent is printed to LogCat is there anyway catch this intent being fired by our app? and therefore releasing the home button has been pressed
     
    haythem souissi
    Greenhorn
    Posts: 4
    Chrome Firefox Browser MS IE
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    KEYCODE_HOME : This key is handled by the frame work and is never delivered to applications.

    So you can't use it
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic