I managed to create a JavaFX application for Android using the client-maven-plugin from Gluon. Everything is fine so far, but I did not manage to react to the native BACK navigation on Android. I tried adding key event listeners to the scene - that works on Desktop and allows reacting to a pressed ESC key, but on Android the event handler isn't even called.
I see, that the event itself reaches the GraalVM and it looks like it is interpreted as a pressed and released BACK key:
02-17 20:46:52.937 8275 8275 V GraalActivity: Activity, process get key event, action = 0
02-17 20:46:52.937 8275 8275 I System.out: KeyEvent: KeyEvent { action=ACTION_DOWN, keyCode=KEYCODE_BACK, scanCode=0, metaState=0, flags=0x48, repeatCount=0, eventTime=244804749, downTime=244804749, deviceId=-1, source=0x101, displayId=0 } with action = 0
02-17 20:46:52.937 8275 8275 I System.out: [JVDBG] eventkeycode = 4 and jfxkc = ESCAPE with code 27
02-17 20:46:52.937 8275 8275 E GraalGluon: Native Dalvik layer has to dispatch key event, pass to native Graal layer with 1 chars...
02-17 20:46:52.937 8275 8275 E GraalGluon: passed count = 1 and realcount = 1
02-17 20:46:52.937 8275 8275 E GraalGluon: c0 = nd c1 = s
02-17 20:46:52.937 8275 8275 E GraalGluon: c0 = 1b and c1 = 7473
02-17 20:46:53.003 8275 8275 V GraalActivity: Activity, process get key event, action = 1
02-17 20:46:53.003 8275 8275 I System.out: KeyEvent: KeyEvent { action=ACTION_UP, keyCode=KEYCODE_BACK, scanCode=0, metaState=0, flags=0x48, repeatCount=0, eventTime=244804818, downTime=244804749, deviceId=-1, source=0x101, displayId=0 } with action = 1
02-17 20:46:53.003 8275 8275 E GraalGluon: Native Dalvik layer has to dispatch key event, pass to native Graal layer with 1 chars...
02-17 20:46:53.003 8275 8275 E GraalGluon: passed count = 1 and realcount = 1
02-17 20:46:53.003 8275 8275 E GraalGluon: c0 = nd c1 = s
02-17 20:46:53.003 8275 8275 E GraalGluon: c0 = 1b and c1 = 7473
My current attempt to capture that keyboard input was
scene.setOnKeyPressed(ev -> {
System.out.println("onKeyPressed: "+ev.getCode() +" bzw. "+ev.getCharacter());
});
but judging from the logs it never gets called.
So: What do I need to do, to handle this event?