From f8cc0164db29084eb048dde194d9a18a0e7d03ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Str=C3=B8mme?= Date: Mon, 15 Jun 2015 13:47:35 +0200 Subject: Android: Always queue calls from Qt to Android. Calling runOnUiThread() only queues calls that comes from a different thread then the UI thread. The problem with the current solution is that we can't promise or rely on the calls being delivered in the same order they were called. Another consequence of the old behavior is that we potentially cause long lasting synchronization points, which can cause the application to become unresponsive or in worst case result in a deadlock. With this change all calls to runAction() will be queued on Android's main message queue (aka the UI thread) and return immediately. Change-Id: I50a4273ae9ba8ad17fb2c50ccd57449e4fbc12f9 Reviewed-by: Eskil Abrahamsen Blomfeldt --- src/android/jar/src/org/qtproject/qt5/android/QtNative.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/android/jar/src/org/qtproject/qt5/android/QtNative.java b/src/android/jar/src/org/qtproject/qt5/android/QtNative.java index a1e7dac4d4..0c01e67637 100644 --- a/src/android/jar/src/org/qtproject/qt5/android/QtNative.java +++ b/src/android/jar/src/org/qtproject/qt5/android/QtNative.java @@ -42,6 +42,8 @@ import android.app.Activity; import android.content.Context; import android.content.Intent; import android.net.Uri; +import android.os.Handler; +import android.os.Looper; import android.text.ClipboardManager; import android.os.Build; import android.util.Log; @@ -173,14 +175,14 @@ public class QtNative m_lostActions.clear(); } - private static boolean runAction(Runnable action) + private static void runAction(Runnable action) { synchronized (m_mainActivityMutex) { - if (m_activity == null) + final Looper mainLooper = Looper.getMainLooper(); + final Handler handler = new Handler(mainLooper); + final boolean actionIsQueued = m_activity != null && mainLooper != null && handler.post(action); + if (!actionIsQueued) m_lostActions.add(action); - else - m_activity.runOnUiThread(action); - return m_activity != null; } } -- cgit v1.2.3