Handle the input like a keyboard event and get the keycode. Cocos api defults KeyCode.MOBILE_BACK to 6 and KeyCode.BACKSPACE to 8 (docs[dot]cocos[dot]com/creator/3.8/api/en/enumeration/KeyCode?id=MOBILE_BACK).
I had to do it manually, because both Android phones here (8.1 and 13) return 8 for both back and backspace.
ie.
input.on(Input.EventType.KEY_DOWN, this.onKeyDown, this);
onKeyDown(event: EventKeyboard) {
if (sys.isMobile) {// just in case
if (event.keyCode == 8) {
// finish and exit here
}
}
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
// Kill the application
//finish();
//System.exit(0);
// Move the task containing this activity to the back of the activity stack.
moveTaskToBack(true);
return true;
}
return super.onKeyDown(keyCode, event);
}