summaryrefslogtreecommitdiffstats
path: root/src/android/jar/src/org/qtproject/qt5/android/QtNative.java
diff options
context:
space:
mode:
authorChristian Strømme <christian.stromme@theqtcompany.com>2015-06-15 13:47:35 +0200
committerChristian Stromme <christian.stromme@theqtcompany.com>2015-09-15 13:23:57 +0000
commitf8cc0164db29084eb048dde194d9a18a0e7d03ed (patch)
tree49c984b874e0f7c3903c7ca9f753472129e062c2 /src/android/jar/src/org/qtproject/qt5/android/QtNative.java
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 <eskil.abrahamsen-blomfeldt@theqtcompany.com>
Diffstat (limited to 'src/android/jar/src/org/qtproject/qt5/android/QtNative.java')
-rw-r--r--src/android/jar/src/org/qtproject/qt5/android/QtNative.java12
1 files changed, 7 insertions, 5 deletions
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;
}
}