path: root/src/android
diff options
authorChristian Strømme <>2015-06-15 13:47:35 +0200
committerChristian Stromme <>2015-09-15 13:23:57 +0000
commitf8cc0164db29084eb048dde194d9a18a0e7d03ed (patch)
tree49c984b874e0f7c3903c7ca9f753472129e062c2 /src/android
parent3601d6d7e3b029dbbfafe2c991537905241016d7 (diff)
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 <>
Diffstat (limited to 'src/android')
1 files changed, 7 insertions, 5 deletions
diff --git a/src/android/jar/src/org/qtproject/qt5/android/ b/src/android/jar/src/org/qtproject/qt5/android/
index a1e7dac4d4..0c01e67637 100644
--- a/src/android/jar/src/org/qtproject/qt5/android/
+++ b/src/android/jar/src/org/qtproject/qt5/android/
@@ -42,6 +42,8 @@ import;
import android.content.Context;
import android.content.Intent;
+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
- 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 &&;
+ if (!actionIsQueued)
- else
- m_activity.runOnUiThread(action);
- return m_activity != null;