@Override public boolean onKeyDown(int keyCode, KeyEvent event) { switch (keyCode) { case KeyEvent.KEYCODE_HOME: Toast.makeText(getApplicationContext(), "Home button pressed", Toast.LENGTH_SHORT).show(); return true; } return super.onKeyDown(keyCode, event); }
How can I detect user pressing Home button in Android
3648
09-Dec-2015
I have used below code. But its not working.
Updated on 27-Jun-2023
Aryan Kumar
27-Jun-2023Sure, here is how to do date comparison validation in Android:
Code snippet
In this code, we first create two Date objects,
date1
anddate2
. Then, we call theisDate1AfterDate2()
method to compare the two dates. TheisDate1AfterDate2()
method returns a boolean value, which indicates whetherdate1
is afterdate2
.Finally, we print a message to the console to indicate the result of the comparison.
Here is an explanation of the code:
Calendar.getInstance()
method returns a Calendar object that represents the current date and time.setTime()
method sets the Calendar object to the specified date.after()
method returns a boolean value, which indicates whether the specified date is after the current date.Manoj Pandey
09-Dec-2015The 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.
Use below code to find home button press.
Create class HomeWatcher class.
Now call on your activity