Android: Create new QtThread when needed
When we quit Qt in an Android app, we also quit the Java thread created to act as the Qt main thread. This works well for normal Qt for Android apps, where the lifetime of the Qt part and the whole Android app is essentially the same. However, in QtQuick for Android Qt can be just a part of the entire app, and the lifecycles are not directly tied. Hence, we might want to quit Qt when the part of the app that has it is not active, and restart it when the Qt part of the app comes active again, and for this we need to create a new QtThread. Set the QtThread variable to null when it has been terminated, and if it's required again, create a new instance. Task-number: QTBUG-130610 Pick-to: 6.8 Change-Id: I430e195fd319a20c9627ed98d6f30858cebc49c4 Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io> (cherry picked from commit 7c7b63f3e85436125baf2211bc5e10556736241b) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
41047e8b2c
commit
35e027fb62
@ -75,9 +75,8 @@ class QtEmbeddedDelegate extends QtActivityDelegateBase
|
|||||||
m_activity.getApplication().unregisterActivityLifecycleCallbacks(this);
|
m_activity.getApplication().unregisterActivityLifecycleCallbacks(this);
|
||||||
QtNative.unregisterAppStateListener(QtEmbeddedDelegate.this);
|
QtNative.unregisterAppStateListener(QtEmbeddedDelegate.this);
|
||||||
QtEmbeddedViewInterfaceFactory.remove(m_activity);
|
QtEmbeddedViewInterfaceFactory.remove(m_activity);
|
||||||
QtNative.terminateQt();
|
QtNative.quitQt();
|
||||||
QtNative.setActivity(null);
|
QtNative.setActivity(null);
|
||||||
QtNative.getQtThread().exit();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -44,7 +44,8 @@ public class QtNative
|
|||||||
|
|
||||||
// a list of all actions which could not be performed (e.g. the main activity is destroyed, etc.)
|
// a list of all actions which could not be performed (e.g. the main activity is destroyed, etc.)
|
||||||
private static final BackgroundActionsTracker m_backgroundActionsTracker = new BackgroundActionsTracker();
|
private static final BackgroundActionsTracker m_backgroundActionsTracker = new BackgroundActionsTracker();
|
||||||
private static final QtThread m_qtThread = new QtThread();
|
private static QtThread m_qtThread = null;
|
||||||
|
private static final Object m_qtThreadLock = new Object();
|
||||||
private static ClassLoader m_classLoader = null;
|
private static ClassLoader m_classLoader = null;
|
||||||
|
|
||||||
private static final Runnable runPendingCppRunnablesRunnable = QtNative::runPendingCppRunnables;
|
private static final Runnable runPendingCppRunnablesRunnable = QtNative::runPendingCppRunnables;
|
||||||
@ -193,7 +194,15 @@ public class QtNative
|
|||||||
}
|
}
|
||||||
|
|
||||||
static QtThread getQtThread() {
|
static QtThread getQtThread() {
|
||||||
|
if (m_qtThread != null)
|
||||||
return m_qtThread;
|
return m_qtThread;
|
||||||
|
|
||||||
|
synchronized (m_qtThreadLock) {
|
||||||
|
if (m_qtThread == null)
|
||||||
|
m_qtThread = new QtThread();
|
||||||
|
|
||||||
|
return m_qtThread;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
interface AppStateDetailsListener {
|
interface AppStateDetailsListener {
|
||||||
@ -339,12 +348,13 @@ public class QtNative
|
|||||||
|
|
||||||
static void startApplication(String params, String mainLib)
|
static void startApplication(String params, String mainLib)
|
||||||
{
|
{
|
||||||
m_qtThread.run(() -> {
|
QtThread thread = getQtThread();
|
||||||
|
thread.run(() -> {
|
||||||
final String qtParams = mainLib + " " + params;
|
final String qtParams = mainLib + " " + params;
|
||||||
if (!startQtAndroidPlugin(qtParams))
|
if (!startQtAndroidPlugin(qtParams))
|
||||||
Log.e(QtTAG, "An error occurred while starting the Qt Android plugin");
|
Log.e(QtTAG, "An error occurred while starting the Qt Android plugin");
|
||||||
});
|
});
|
||||||
m_qtThread.post(QtNative::startQtApplication);
|
thread.post(QtNative::startQtApplication);
|
||||||
waitForServiceSetup();
|
waitForServiceSetup();
|
||||||
m_stateDetails.isStarted = true;
|
m_stateDetails.isStarted = true;
|
||||||
notifyAppStateDetailsChanged(m_stateDetails);
|
notifyAppStateDetailsChanged(m_stateDetails);
|
||||||
@ -363,6 +373,17 @@ public class QtNative
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void quitQt()
|
||||||
|
{
|
||||||
|
terminateQt();
|
||||||
|
m_stateDetails.isStarted = false;
|
||||||
|
notifyAppStateDetailsChanged(m_stateDetails);
|
||||||
|
getQtThread().exit();
|
||||||
|
synchronized (m_qtThreadLock) {
|
||||||
|
m_qtThread = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@UsedFromNativeCode
|
@UsedFromNativeCode
|
||||||
static int checkSelfPermission(String permission)
|
static int checkSelfPermission(String permission)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user