From 849107cfc816134c5ccd07a45a0834df31060ca4 Mon Sep 17 00:00:00 2001 From: Aayush Sarikhada Date: Sun, 31 Aug 2025 00:05:28 +0530 Subject: [PATCH] Fix Android back gesture failing after keyboard dismissal (#109806) Reason of bug: This happened because the text input field was still receiving the first back gesture event instead of letting it reach the main app. --- .../org/godotengine/godot/input/GodotEditText.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/platform/android/java/lib/src/org/godotengine/godot/input/GodotEditText.java b/platform/android/java/lib/src/org/godotengine/godot/input/GodotEditText.java index afaafe1d9fc..4444f068512 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/input/GodotEditText.java +++ b/platform/android/java/lib/src/org/godotengine/godot/input/GodotEditText.java @@ -221,7 +221,15 @@ public class GodotEditText extends EditText { public boolean onKeyDown(final int keyCode, final KeyEvent keyEvent) { /* Let SurfaceView get focus if back key is input. */ if (keyCode == KeyEvent.KEYCODE_BACK) { + // Clear focus from EditText immediately + clearFocus(); + + // Transfer focus to render view mRenderView.getView().requestFocus(); + + // Forward this back key event to the render view's input handler + // since we're no longer the focused view + return mRenderView.getInputHandler().onKeyDown(keyCode, keyEvent); } // When a hardware keyboard is connected, all key events come through so we can route them @@ -248,6 +256,11 @@ public class GodotEditText extends EditText { return mRenderView.getInputHandler().onKeyUp(keyCode, keyEvent); } + // If this is a BACK key and we don't have focus anymore, forward to render view + if (keyCode == KeyEvent.KEYCODE_BACK && !hasFocus()) { + return mRenderView.getInputHandler().onKeyUp(keyCode, keyEvent); + } + if (needHandlingInGodot(keyCode, keyEvent) && mRenderView.getInputHandler().onKeyUp(keyCode, keyEvent)) { return true; } else {