From 23ac125bcb750575b86edfaa08448f8358260e4b Mon Sep 17 00:00:00 2001 From: BogDan Vatra Date: Mon, 13 Jun 2016 17:05:43 +0300 Subject: Android: don't wait if the event loop is stopped QAndroidEventDispatcherStopper is stopped when the application is in background and the user uses the task manager to kill the task. If the application has services the task manager doesn't kills it, but instead it tries to gently terminate the activity. The problem is that the activity is still backgrounded (meaning that the Qt event loop is freezed), therefore terminateQt will hang. Task-number: QTBUG-54012 Change-Id: I6e333cbcaf41e9e298eeb8b2b0bc3adcf446783f Reviewed-by: Christian Stromme --- src/plugins/platforms/android/androidjnimain.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'src/plugins/platforms/android/androidjnimain.cpp') diff --git a/src/plugins/platforms/android/androidjnimain.cpp b/src/plugins/platforms/android/androidjnimain.cpp index 671dad98b2..fe2401f561 100644 --- a/src/plugins/platforms/android/androidjnimain.cpp +++ b/src/plugins/platforms/android/androidjnimain.cpp @@ -539,8 +539,11 @@ static void quitQtAndroidPlugin(JNIEnv *env, jclass /*clazz*/) static void terminateQt(JNIEnv *env, jclass /*clazz*/) { - sem_wait(&m_terminateSemaphore); - sem_destroy(&m_terminateSemaphore); + // QAndroidEventDispatcherStopper is stopped when the user uses the task manager to kill the application + if (!QAndroidEventDispatcherStopper::instance()->stopped()) { + sem_wait(&m_terminateSemaphore); + sem_destroy(&m_terminateSemaphore); + } env->DeleteGlobalRef(m_applicationClass); env->DeleteGlobalRef(m_classLoaderObject); if (m_resourcesObj) @@ -558,8 +561,11 @@ static void terminateQt(JNIEnv *env, jclass /*clazz*/) m_androidPlatformIntegration = nullptr; delete m_androidAssetsFileEngineHandler; m_androidAssetsFileEngineHandler = nullptr; - sem_post(&m_exitSemaphore); - pthread_join(m_qtAppThread, nullptr); + + if (!QAndroidEventDispatcherStopper::instance()->stopped()) { + sem_post(&m_exitSemaphore); + pthread_join(m_qtAppThread, nullptr); + } } static void setSurface(JNIEnv *env, jobject /*thiz*/, jint id, jobject jSurface, jint w, jint h) -- cgit v1.2.3