Commit f8cc0164 authored by Christian Strømme's avatar Christian Strømme Committed by Christian Stromme
Browse files

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: default avatarEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@theqtcompany.com>
parent 3601d6d7
No related merge requests found
Showing with 7 additions and 5 deletions
......@@ -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;
}
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment