From fbc78ff287586349600e508d55fde332def55b6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tinja=20Paavosepp=C3=A4?= Date: Tue, 26 Nov 2024 14:17:38 +0200 Subject: [PATCH] Android: Do not start Qt app if it has already been started Call startQtApplication() in QtView even if the Qt libs have already been loaded, to make sure the app gets started also when the Activity is recreated. Check whether Qt app is already running inside the method itself to avoid hanging up because of trying to start it twice. Task-number: QTBUG-123711 Pick-to: 6.8 Change-Id: I3b009e4c2f40af9f258ce32b7e181c3faa21c194 Reviewed-by: Petri Virkkunen Reviewed-by: Assam Boudjelthia (cherry picked from commit be33f2d3233fb787d5251ba7d0876962efe49075) Reviewed-by: Qt Cherry-pick Bot --- .../jar/src/org/qtproject/qt/android/QtNative.java | 3 +++ .../jar/src/org/qtproject/qt/android/QtView.java | 10 +++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/android/jar/src/org/qtproject/qt/android/QtNative.java b/src/android/jar/src/org/qtproject/qt/android/QtNative.java index 81ef78a8e2c..33ffd58482f 100644 --- a/src/android/jar/src/org/qtproject/qt/android/QtNative.java +++ b/src/android/jar/src/org/qtproject/qt/android/QtNative.java @@ -348,6 +348,9 @@ public class QtNative static void startApplication(String params, String mainLib) { + if (m_stateDetails.isStarted) + return; + QtThread thread = getQtThread(); thread.run(() -> { final String qtParams = mainLib + " " + params; diff --git a/src/android/jar/src/org/qtproject/qt/android/QtView.java b/src/android/jar/src/org/qtproject/qt/android/QtView.java index babc766077e..55878209fed 100644 --- a/src/android/jar/src/org/qtproject/qt/android/QtView.java +++ b/src/android/jar/src/org/qtproject/qt/android/QtView.java @@ -148,14 +148,14 @@ abstract class QtView extends ViewGroup { loader.setMainLibraryName(appLibName); QtLoader.LoadingResult result = loader.loadQtLibraries(); - if (result == QtLoader.LoadingResult.Succeeded) { - // Start Native Qt application - m_viewInterface.startQtApplication(loader.getApplicationParameters(), - loader.getMainLibraryPath()); - } else if (result == QtLoader.LoadingResult.Failed) { + if (result == QtLoader.LoadingResult.Failed) { // If we weren't able to load the libraries, remove the delegate from the factory // as it's holding a reference to the Context, and we don't want it leaked QtEmbeddedViewInterfaceFactory.remove(getContext()); + } else { + // Start Native Qt application + m_viewInterface.startQtApplication(loader.getApplicationParameters(), + loader.getMainLibraryPath()); } }