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>
This commit is contained in:
parent
3601d6d7e3
commit
f8cc0164db
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user