diff --git a/src/android/jar/src/org/qtproject/qt/android/BackendRegister.java b/src/android/jar/src/org/qtproject/qt/android/BackendRegister.java index b66a593ec6b..590c7d84aac 100644 --- a/src/android/jar/src/org/qtproject/qt/android/BackendRegister.java +++ b/src/android/jar/src/org/qtproject/qt/android/BackendRegister.java @@ -4,6 +4,7 @@ class BackendRegister { + static native boolean isNull(); static native void registerBackend(Class interfaceType, Object interfaceObject); static native void unregisterBackend(Class interfaceType); } diff --git a/src/android/jar/src/org/qtproject/qt/android/QtActivityDelegate.java b/src/android/jar/src/org/qtproject/qt/android/QtActivityDelegate.java index 07ca4daeba7..e1292eed87a 100644 --- a/src/android/jar/src/org/qtproject/qt/android/QtActivityDelegate.java +++ b/src/android/jar/src/org/qtproject/qt/android/QtActivityDelegate.java @@ -59,8 +59,9 @@ void initMembers() void registerBackends() { - if (m_backendsRegistered) + if (m_backendsRegistered || BackendRegister.isNull()) return; + m_backendsRegistered = true; BackendRegister.registerBackend(QtWindowInterface.class, QtActivityDelegate.this); BackendRegister.registerBackend(QtAccessibilityInterface.class, QtActivityDelegate.this); @@ -74,6 +75,10 @@ void unregisterBackends() return; m_backendsRegistered = false; + + if (BackendRegister.isNull()) + return; + BackendRegister.unregisterBackend(QtWindowInterface.class); BackendRegister.unregisterBackend(QtAccessibilityInterface.class); BackendRegister.unregisterBackend(QtMenuInterface.class); diff --git a/src/android/jar/src/org/qtproject/qt/android/QtEmbeddedDelegate.java b/src/android/jar/src/org/qtproject/qt/android/QtEmbeddedDelegate.java index fb1ddd9907e..67175370e6f 100644 --- a/src/android/jar/src/org/qtproject/qt/android/QtEmbeddedDelegate.java +++ b/src/android/jar/src/org/qtproject/qt/android/QtEmbeddedDelegate.java @@ -88,12 +88,19 @@ public void onAppStateDetailsChanged(QtNative.ApplicationStateDetails details) { synchronized (this) { m_stateDetails = details; if (details.isStarted && !m_backendsRegistered) { + if (BackendRegister.isNull()) + return; + m_backendsRegistered = true; BackendRegister.registerBackend(QtWindowInterface.class, this); BackendRegister.registerBackend(QtMenuInterface.class, this); BackendRegister.registerBackend(QtInputInterface.class, m_inputDelegate); } else if (!details.isStarted && m_backendsRegistered) { m_backendsRegistered = false; + + if (BackendRegister.isNull()) + return; + BackendRegister.unregisterBackend(QtWindowInterface.class); BackendRegister.unregisterBackend(QtMenuInterface.class); BackendRegister.unregisterBackend(QtInputInterface.class); diff --git a/src/plugins/platforms/android/androidbackendregister.cpp b/src/plugins/platforms/android/androidbackendregister.cpp index bfd86138aa5..98f0ea59356 100644 --- a/src/plugins/platforms/android/androidbackendregister.cpp +++ b/src/plugins/platforms/android/androidbackendregister.cpp @@ -14,10 +14,16 @@ Q_DECLARE_JNI_CLASS(BackendRegister, "org/qtproject/qt/android/BackendRegister") bool AndroidBackendRegister::registerNatives() { return QtJniTypes::BackendRegister::registerNativeMethods( - { Q_JNI_NATIVE_SCOPED_METHOD(registerBackend, AndroidBackendRegister), + { Q_JNI_NATIVE_SCOPED_METHOD(isNull, AndroidBackendRegister), + Q_JNI_NATIVE_SCOPED_METHOD(registerBackend, AndroidBackendRegister), Q_JNI_NATIVE_SCOPED_METHOD(unregisterBackend, AndroidBackendRegister) }); } +jboolean AndroidBackendRegister::isNull(JNIEnv *, jclass) +{ + return QtAndroid::backendRegister() == nullptr; +} + void AndroidBackendRegister::registerBackend(JNIEnv *, jclass, jclass interfaceClass, jobject interface) { diff --git a/src/plugins/platforms/android/androidbackendregister.h b/src/plugins/platforms/android/androidbackendregister.h index 502880a77f3..06b7b832416 100644 --- a/src/plugins/platforms/android/androidbackendregister.h +++ b/src/plugins/platforms/android/androidbackendregister.h @@ -60,6 +60,8 @@ class AndroidBackendRegister QMutex m_registerMutex; QMap m_register; + static jboolean isNull(JNIEnv *, jclass); + Q_DECLARE_JNI_NATIVE_METHOD_IN_CURRENT_SCOPE(isNull) static void registerBackend(JNIEnv *, jclass, jclass interfaceClass, jobject interface); Q_DECLARE_JNI_NATIVE_METHOD_IN_CURRENT_SCOPE(registerBackend) static void unregisterBackend(JNIEnv *, jclass, jclass interfaceClass);