summarylogtreecommitdiffstats
path: root/0020-Allow-handling-Android-activity-lifecycle-by-user-pr.patch
blob: 1218a79b0df586c10c3fb7fafcf777250ecc1124 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
From e23994459a5ad11c367465a3c287d4e409963efe Mon Sep 17 00:00:00 2001
From: Martchus <martchus@gmx.net>
Date: Thu, 16 Jan 2025 21:21:50 +0100
Subject: [PATCH 20/20] Allow handling Android activity lifecycle by user
 provided methods

Change-Id: I52107fadaea431c2932c1a1948ca7d2c889abd6d
---
 .../qtproject/qt/android/QtActivityBase.java  | 25 +++++++++++++++----
 1 file changed, 20 insertions(+), 5 deletions(-)

diff --git a/src/android/jar/src/org/qtproject/qt/android/QtActivityBase.java b/src/android/jar/src/org/qtproject/qt/android/QtActivityBase.java
index 79c67d87823..cac5fb7200b 100644
--- a/src/android/jar/src/org/qtproject/qt/android/QtActivityBase.java
+++ b/src/android/jar/src/org/qtproject/qt/android/QtActivityBase.java
@@ -73,7 +73,7 @@ public class QtActivityBase extends Activity
         m_isCustomThemeSet = true;
     }
 
-    private void restartApplication() {
+    protected void restartApplication() {
         Intent intent = Intent.makeRestartActivityTask(getComponentName());
         startActivity(intent);
         QtNative.quitApp();
@@ -85,6 +85,11 @@ public class QtActivityBase extends Activity
         m_delegate = new QtActivityDelegate(this);
     }
 
+    protected boolean handleRestart(Bundle savedInstanceState)
+    {
+        return false;
+    }
+
     @Override
     protected void onCreate(Bundle savedInstanceState)
     {
@@ -97,7 +102,7 @@ public class QtActivityBase extends Activity
                     android.R.style.Theme_Holo_Light);
         }
 
-        if (QtNative.getStateDetails().isStarted) {
+        if (QtNative.getStateDetails().isStarted && !handleRestart(savedInstanceState)) {
             // We don't yet have a reliable way to keep the app
             // running properly in case of an Activity only restart,
             // so for now restart the whole app.
@@ -168,16 +173,26 @@ public class QtActivityBase extends Activity
         QtNative.setApplicationState(QtNative.ApplicationState.ApplicationSuspended);
     }
 
+    protected boolean handleDestruction()
+    {
+        return false;
+    }
+
     @Override
     protected void onDestroy()
     {
         super.onDestroy();
+        boolean destructionHandled = handleDestruction();
         if (!m_retainNonConfigurationInstance) {
             QtNative.unregisterAppStateListener(m_delegate);
-            QtNative.terminateQt();
+            if (!destructionHandled) {
+                QtNative.terminateQt();
+            }
             QtNative.setActivity(null);
-            QtNative.getQtThread().exit();
-            System.exit(0);
+            if (!destructionHandled) {
+                QtNative.getQtThread().exit();
+                System.exit(0);
+            }
         }
     }
 
-- 
2.48.1