• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Intercept HOME button click

 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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,
 
Rancher
Posts: 1369
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
     
    Greenhorn
    Posts: 1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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
     
    Greenhorn
    Posts: 4
    MS IE Firefox Browser Chrome
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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
     
    Consider Paul's rocket mass heater.
    reply
      Bookmark Topic Watch Topic
    • New Topic