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 <assam.boudjelthia@qt.io>
This commit is contained in:
Petri Virkkunen 2025-01-24 15:35:00 +02:00
parent 61c6e90401
commit 34a4acfb14

View File

@ -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);
}
}
}