From ec9eb9d90b924909b7c6c8127a607b6d0b000975 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tinja=20Paavosepp=C3=A4?= Date: Thu, 22 Feb 2024 14:05:11 +0200 Subject: [PATCH] Android: Add QtEditText to QtWindow in constructor Of course, createSurface() is called more than once, for example when coming back from the background, and you cannot add a View to the layout more than once, since this leads to an uncaught exception and a crash. So add the QtEditText once, in the constructor, as is indeed sensible. Fixes: QTBUG-122648 Change-Id: I7ef48951cd8a1c99935f5e96c70b6dbf0c745803 Reviewed-by: Assam Boudjelthia (cherry picked from commit 211e51b81ec9800161d0a98c6f70c747701035e8) Reviewed-by: Qt Cherry-pick Bot --- src/android/jar/src/org/qtproject/qt/android/QtWindow.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/android/jar/src/org/qtproject/qt/android/QtWindow.java b/src/android/jar/src/org/qtproject/qt/android/QtWindow.java index bac06f7f566..86d5e9b4484 100644 --- a/src/android/jar/src/org/qtproject/qt/android/QtWindow.java +++ b/src/android/jar/src/org/qtproject/qt/android/QtWindow.java @@ -33,6 +33,8 @@ class QtWindow extends QtLayout implements QtSurfaceInterface { m_editText = new QtEditText(context, delegate); setParent(parentWindow); setFocusableInTouchMode(true); + addView(m_editText, new QtLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, + ViewGroup.LayoutParams.MATCH_PARENT)); QtNative.runAction(() -> { m_gestureDetector = @@ -111,8 +113,6 @@ class QtWindow extends QtLayout implements QtSurfaceInterface { // The surface container of this window will be added as the first of the stack. // All other views are stacked based on the order they are created. addView(m_surfaceContainer, 0); - addView(m_editText, new QtLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, - ViewGroup.LayoutParams.MATCH_PARENT)); }); }