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.7
Change-Id: I79f0c53c815bf71c831d0b930f358c9fd820a2d4
Reviewed-by: Tinja Paavoseppä <tinja.paavoseppa@qt.io>
(cherry picked from commit 7602f71aa6cd10ff1b16d154fa967c8fce8e8d0a)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Assam Boudjelthia 2024-06-12 13:05:16 +03:00 committed by Qt Cherry-pick Bot
parent 294f257a0a
commit fcae2b7f2d
3 changed files with 14 additions and 44 deletions

View File

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

View File

@ -97,21 +97,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)
{

View File

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