From 4dbdb5735883e9c4666cb6afa8f672026fed64f6 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 Change-Id: I3b009e4c2f40af9f258ce32b7e181c3faa21c194 Reviewed-by: Petri Virkkunen Reviewed-by: Assam Boudjelthia (cherry picked from commit be33f2d3233fb787d5251ba7d0876962efe49075) Reviewed-by: Qt Cherry-pick Bot (cherry picked from commit fbc78ff287586349600e508d55fde332def55b6d) --- .../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 e8e152e8b4..f4e76d0835 100644 --- a/src/android/jar/src/org/qtproject/qt/android/QtNative.java +++ b/src/android/jar/src/org/qtproject/qt/android/QtNative.java @@ -340,6 +340,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 9e8ed5b2da..0239771bbd 100644 --- a/src/android/jar/src/org/qtproject/qt/android/QtView.java +++ b/src/android/jar/src/org/qtproject/qt/android/QtView.java @@ -155,14 +155,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()); } }