Enable QtAndroid::runOnAndroidThread in a Service

Change-Id: I214f5dc70c52011a5e1712ea70f97f8b564fb664
Reviewed-by: BogDan Vatra <bogdan@kdab.com>
This commit is contained in:
Heikki Haveri 2017-01-12 14:27:49 +02:00 committed by BogDan Vatra
parent cab4d495b2
commit aebf66d242
2 changed files with 17 additions and 6 deletions

View File

@ -243,13 +243,24 @@ public class QtNative
}
}
private static void runPendingCppRunnablesOnUiThread()
private static void runPendingCppRunnablesOnAndroidThread()
{
synchronized (m_mainActivityMutex) {
if (!m_activityPaused && m_activity != null)
m_activity.runOnUiThread(runPendingCppRunnablesRunnable);
else
runAction(runPendingCppRunnablesRunnable);
if (m_activity != null) {
if (!m_activityPaused)
m_activity.runOnUiThread(runPendingCppRunnablesRunnable);
else
runAction(runPendingCppRunnablesRunnable);
} else {
final Looper mainLooper = Looper.getMainLooper();
final Thread looperThread = mainLooper.getThread();
if (looperThread.equals(Thread.currentThread())) {
runPendingCppRunnablesRunnable.run();
} else {
final Handler handler = new Handler(mainLooper);
handler.post(runPendingCppRunnablesRunnable);
}
}
}
}

View File

@ -393,7 +393,7 @@ jint QtAndroidPrivate::initJNI(JavaVM *vm, JNIEnv *env)
return JNI_ERR;
g_runPendingCppRunnablesMethodID = env->GetStaticMethodID(jQtNative,
"runPendingCppRunnablesOnUiThread",
"runPendingCppRunnablesOnAndroidThread",
"()V");
g_hideSplashScreenMethodID = env->GetStaticMethodID(jQtNative, "hideSplashScreen", "()V");
g_jNativeClass = static_cast<jclass>(env->NewGlobalRef(jQtNative));