I have this method in one of my Android Activities:
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if(keyCode == KeyEvent.KEYCODE_BACK) { Log.d("Test", "Back button pressed!"); } else if(keyCode == KeyEvent.KEYCODE_HOME) { Log.d("Test", "Home button pressed!"); } return super.onKeyDown(keyCode, event); }
But, even though the KEYCODE_HOME is valid, the log method never fires. This works for the back button though. Does anyone know why this is and how to get this to work?
Pressing the Home key allows the user to start a new Task, by showing the launcher. All active Tasks (and therefore Activities incl. your "Air Control" example) will call their onPause() method.
This answer is useful. 0. This answer is not useful. Show activity on this post. The activities onPause() is called when pressing the home or back button.
onPause() is called when Home button is pressed.
Note: onDestroy() method not call after press Home Button.
The Home button is a very dangerous button to override and, because of that, Android will not let you override its behavior the same way you do the BACK button.
Take a look at this discussion.
You will notice that the home button seems to be implemented as a intent invocation, so you'll end up having to add an intent category to your activity. Then, any time the user hits home, your app will show up as an option. You should consider what it is you are looking to accomplish with the home button. If its not to replace the default home screen of the device, I would be wary of overloading the HOME button, but it is possible (per discussion in above thread.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With