Hi,
I want to handle key press and long key press for the key code KEYCODE_BACK(back button). can any one suggest me how to do this in android 1.5(API level 3).
Here is the code.
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
if(event.getRepeatCount()==0) {
// normal key press
//Do something here
// But problem is, this code is hitting for long press also, how to avoid this
} else {
// Long key press
//Do something here
}
// Always consume back key event by returning true
//so that default behavior of back is overrided
return true;
}
return super.onKeyDown(keyCode, event);
}
The problem is the code for normal key press is also executed on long press. I want to avoid this.
Note: I can't use methods like onKeyLongPress()
, startTracking()
etc as they are introduced in API level 5