How To Detect Hard/soft Back Button On Android Device?
I want to know how to detect hard or soft 'BACK Button' on device? I searched but mostly I found this code @Override public boolean onKeyDown(int keyCode, KeyEvent event) {
Solution 1:
I think this should work
Queries the framework about whether any physical keys exist on the any keyboard attached to the device that are capable of producing the given key code.
booleanhasBackKey= KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK);
Android developer documentation
Solution 2:
the best way is to overide the onBackPress(),becuase whatever the functionality you want to achieve onBackpress key event,you can also do that in onBackPress() method.
@OverridepublicvoidonBackPressed() {
// TODO Auto-generated method stub// do your stuff heresuper.onBackPressed();
}
Solution 3:
You can do this by overriding the method
@OverridepublicvoidonBackPressed() {
// TODO Auto-generated method stubsuper.onBackPressed();
}
Post a Comment for "How To Detect Hard/soft Back Button On Android Device?"