summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTinja Paavoseppä <tinja.paavoseppa@qt.io>2024-02-22 15:08:06 +0200
committerTinja Paavoseppä <tinja.paavoseppa@qt.io>2024-03-07 12:39:23 +0000
commit0533f7c075863b7c1541a5caa8340158923a8569 (patch)
treeeb48fa36a053bb75a9d21826ddcb1294b2e0bcbe
parent44ee8df9c73cc712021f10ecb5df399765a6a6af (diff)
Android: Synchronize window creation in QtEmbeddedDelegate
Qt window loading is initiated either when the QtView is attached to its Android window, or when the Android QPA plugin has been loaded and is ready, depending on the order. Since the window attachment happens in the Android UI thread, and the Android QPA plugin callback happens in Qt thread, add synchronized block to make sure the execution stays ordered. Fixes: QTBUG-122626 Change-Id: Id476032f02aa8990432a02f62b6bf6237a17e7ac Reviewed-by: Tinja Paavoseppä <tinja.paavoseppa@qt.io>
-rw-r--r--src/android/jar/src/org/qtproject/qt/android/QtEmbeddedDelegate.java35
1 files changed, 23 insertions, 12 deletions
diff --git a/src/android/jar/src/org/qtproject/qt/android/QtEmbeddedDelegate.java b/src/android/jar/src/org/qtproject/qt/android/QtEmbeddedDelegate.java
index 43cde0cb33..e18d0953c3 100644
--- a/src/android/jar/src/org/qtproject/qt/android/QtEmbeddedDelegate.java
+++ b/src/android/jar/src/org/qtproject/qt/android/QtEmbeddedDelegate.java
@@ -28,6 +28,7 @@ class QtEmbeddedDelegate extends QtActivityDelegateBase implements QtNative.AppS
private QtView m_view;
private long m_rootWindowRef = 0L;
private QtNative.ApplicationStateDetails m_stateDetails;
+ private boolean m_windowLoaded = false;
private static native void createRootWindow(View rootView);
static native void deleteWindow(long windowReference);
@@ -91,16 +92,18 @@ class QtEmbeddedDelegate extends QtActivityDelegateBase implements QtNative.AppS
@Override
public void onAppStateDetailsChanged(QtNative.ApplicationStateDetails details) {
- m_stateDetails = details;
- if (m_stateDetails.nativePluginIntegrationReady) {
- QtNative.runAction(() -> {
- DisplayMetrics metrics = Resources.getSystem().getDisplayMetrics();
- QtDisplayManager.setApplicationDisplayMetrics(m_activity,
- metrics.widthPixels,
- metrics.heightPixels);
- if (m_view != null)
- createRootWindow(m_view);
- });
+ synchronized (this) {
+ m_stateDetails = details;
+ if (m_stateDetails.nativePluginIntegrationReady) {
+ QtNative.runAction(() -> {
+ DisplayMetrics metrics = Resources.getSystem().getDisplayMetrics();
+ QtDisplayManager.setApplicationDisplayMetrics(m_activity,
+ metrics.widthPixels,
+ metrics.heightPixels);
+
+ });
+ createRootWindow();
+ }
}
}
@@ -130,8 +133,9 @@ class QtEmbeddedDelegate extends QtActivityDelegateBase implements QtNative.AppS
public void queueLoadWindow()
{
- if (m_stateDetails.nativePluginIntegrationReady) {
- createRootWindow(m_view);
+ synchronized (this) {
+ if (m_stateDetails.nativePluginIntegrationReady)
+ createRootWindow();
}
}
@@ -150,4 +154,11 @@ class QtEmbeddedDelegate extends QtActivityDelegateBase implements QtNative.AppS
deleteWindow(m_rootWindowRef);
m_rootWindowRef = 0L;
}
+
+ private void createRootWindow() {
+ if (m_view != null && !m_windowLoaded) {
+ createRootWindow(m_view);
+ m_windowLoaded = true;
+ }
+ }
}