I want to finish the Activity on Home Button Click . I have below code but not get its click event . but still not get clickevent
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_DOWN) {
switch (keyCode) {
case KeyEvent.KEYCODE_HOME:
System.out.println("Home clicked....");
return true;
}
}
return super.onKeyDown(keyCode, event);
}
When Home button is pressed, onStop method is called in your activity. So what you may do is to add finish();
in onStop method to destroy your activity. Eventually onDestroy method will be raised to confirm that your activity is finished.
You can't handle "Home" button.
You could try overriding some of these methods though: onStop, onUserLeaveHint
Are you sure you need to do this though?
If you could save your current state through the onPause/onSaveInstanceState and recover it later the OS should be able to handle the Activity's life cycle and finish it if needed.
Can you tell us what is preventing you from doing it that way? :)
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