diff options
author | Assam Boudjelthia <[email protected]> | 2024-06-12 13:05:16 +0300 |
---|---|---|
committer | Assam Boudjelthia <[email protected]> | 2024-06-13 01:28:36 +0300 |
commit | 7602f71aa6cd10ff1b16d154fa967c8fce8e8d0a (patch) | |
tree | 2ece61eea340f9736d8e2c3015a2d14f9f07cdce | |
parent | a843db6e2d80a99be38c2b66aac92cb912613bd6 (diff) |
Android: restart whole app if the activity was restarted
If the Activity restart path is run while m_layout is null,
it would lead to a NullPointerException when trying to
access m_layout. Moreover, the code here doesn't make sense,
as m_layout.getParent() should probably be only done when
super.updateActivityAfterRestart() returns true because if
it returns false, the app will be restarted anyway.
Testing the restarting behavior of the Activity, it seems
that the code code doesn't really work in bringing the app
to a usable state after an activity restart, and this code
path should be re-evaluated. Thus, I'm simplifying the logic
to only restart the whole app, and later figure out a way to
do a proper smooth transition instead.
Fixes: QTBUG-124786
Pick-to: 6.8 6.7
Change-Id: I79f0c53c815bf71c831d0b930f358c9fd820a2d4
Reviewed-by: Tinja Paavoseppä <[email protected]>
3 files changed, 14 insertions, 44 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 b5de60d49d7..dccaf45a05e 100644 --- a/src/android/jar/src/org/qtproject/qt/android/QtActivityBase.java +++ b/src/android/jar/src/org/qtproject/qt/android/QtActivityBase.java @@ -63,25 +63,19 @@ public class QtActivityBase extends Activity implements QtNative.AppStateDetails m_applicationParams += params; } - private void handleActivityRestart() { - if (QtNative.getStateDetails().isStarted) { - boolean updated = m_delegate.updateActivityAfterRestart(this); - if (!updated) { - // could not update the activity so restart the application - Intent intent = Intent.makeRestartActivityTask(getComponentName()); - startActivity(intent); - QtNative.quitApp(); - Runtime.getRuntime().exit(0); - } - } - } - @Override public void setTheme(int resId) { super.setTheme(resId); m_isCustomThemeSet = true; } + private void restartApplication() { + Intent intent = Intent.makeRestartActivityTask(getComponentName()); + startActivity(intent); + QtNative.quitApp(); + Runtime.getRuntime().exit(0); + } + @Override protected void onCreate(Bundle savedInstanceState) { @@ -94,11 +88,17 @@ public class QtActivityBase extends Activity implements QtNative.AppStateDetails android.R.style.Theme_Holo_Light); } + if (QtNative.getStateDetails().isStarted) { + // 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. + restartApplication(); + } + m_delegate = new QtActivityDelegate(this); QtNative.registerAppStateListener(this); - handleActivityRestart(); addReferrer(getIntent()); QtActivityLoader loader = new QtActivityLoader(this); 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 596074c6310..d78c059094b 100644 --- a/src/android/jar/src/org/qtproject/qt/android/QtActivityDelegate.java +++ b/src/android/jar/src/org/qtproject/qt/android/QtActivityDelegate.java @@ -98,21 +98,6 @@ class QtActivityDelegate extends QtActivityDelegateBase } @Override - public boolean updateActivityAfterRestart(Activity activity) { - boolean updated = super.updateActivityAfterRestart(activity); - // TODO verify whether this is even needed, the last I checked the initMembers - // recreates the layout anyway - // update the new activity content view to old layout - ViewGroup layoutParent = (ViewGroup)m_layout.getParent(); - if (layoutParent != null) - layoutParent.removeView(m_layout); - - m_activity.setContentView(m_layout); - - return updated; - } - - @Override void startNativeApplicationImpl(String appParams, String mainLib) { m_layout.getViewTreeObserver().addOnGlobalLayoutListener( diff --git a/src/android/jar/src/org/qtproject/qt/android/QtActivityDelegateBase.java b/src/android/jar/src/org/qtproject/qt/android/QtActivityDelegateBase.java index 4980a47d08d..84a5961b8a6 100644 --- a/src/android/jar/src/org/qtproject/qt/android/QtActivityDelegateBase.java +++ b/src/android/jar/src/org/qtproject/qt/android/QtActivityDelegateBase.java @@ -77,21 +77,6 @@ abstract class QtActivityDelegateBase return m_contextMenuVisible; } - public boolean updateActivityAfterRestart(Activity activity) { - try { - // set new activity - m_activity = activity; - QtNative.setActivity(m_activity); - - // force c++ native activity object to update - return QtNative.updateNativeActivity(); - } catch (Exception e) { - Log.w(QtNative.QtTAG, "Failed to update the activity."); - e.printStackTrace(); - return false; - } - } - public void startNativeApplication(String appParams, String mainLib) { if (m_membersInitialized) |