From 34a4acfb14f0ced0f8df8a72b08f41840cab1b7b Mon Sep 17 00:00:00 2001 From: Petri Virkkunen Date: Fri, 24 Jan 2025 15:35:00 +0200 Subject: [PATCH] QQ4A: QtView will listen to Application state ... and remove itself from the view hierarchy when the Qt application is no longer running, i.e. when quitQt() has been called after returning from main(). Change-Id: I6898be4e48673271109aaef718fe3f0d2ba4406f Reviewed-by: Assam Boudjelthia --- .../jar/src/org/qtproject/qt/android/QtView.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/android/jar/src/org/qtproject/qt/android/QtView.java b/src/android/jar/src/org/qtproject/qt/android/QtView.java index 55878209fed..9b8bf5413b9 100644 --- a/src/android/jar/src/org/qtproject/qt/android/QtView.java +++ b/src/android/jar/src/org/qtproject/qt/android/QtView.java @@ -15,7 +15,7 @@ import java.util.Objects; // Base class for embedding QWindow into native Android view hierarchy. Extend to implement // the creation of appropriate window to embed. -abstract class QtView extends ViewGroup { +abstract class QtView extends ViewGroup implements QtNative.AppStateDetailsListener { private final static String TAG = "QtView"; interface QtWindowListener { @@ -48,7 +48,7 @@ abstract class QtView extends ViewGroup { **/ QtView(Context context) { super(context); - + QtNative.registerAppStateListener(this); m_viewInterface = QtEmbeddedViewInterfaceFactory.create(context); addOnLayoutChangeListener( (v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> { @@ -204,4 +204,13 @@ abstract class QtView extends ViewGroup { QtWindow getQtWindow() { return m_window; } + + @Override + public void onAppStateDetailsChanged(QtNative.ApplicationStateDetails details) { + if (!details.isStarted) { + ViewGroup parent = (ViewGroup)getParent(); + if (parent != null) + parent.removeView(this); + } + } }