Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(android)(8_1_X): Closing root window from child window causes app exit issues as of 8.0.1 #11093

Merged
merged 3 commits into from
Aug 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -951,7 +951,7 @@ public void onBackPressed()
}

// Handle app exit ourselves since the above window proxy did not handle the back event.
boolean exitOnClose = true;
boolean exitOnClose = (TiActivityWindows.getWindowCount() <= 1);
if (this.window != null) {
exitOnClose = TiConvert.toBoolean(this.window.getProperty(TiC.PROPERTY_EXIT_ON_CLOSE), exitOnClose);
}
Expand Down Expand Up @@ -1689,19 +1689,33 @@ protected void fireOnDestroy()

private boolean shouldFinishRootActivity()
{
// Do not finish root activity if disabled globally. (Typically done when restarting LiveView.)
if (TiBaseActivity.canFinishRoot == false) {
return false;
}

// This method only applies to "Ti.UI.Window" based activities.
// If this is the root activity, then let it do its default finish handling.
if (this instanceof TiRootActivity) {
return false;
}

boolean exitOnClose = (TiActivityWindows.getWindowCount() <= 1);
// Determine if this activity's "Ti.UI.Window" reference is still in the global collection.
// - Will not be in the collection if its close() method was called.
// - Will be in collection when pressing Back button or finish() was called natively.
boolean isTiWindowOpen = false;
if (this.launchIntent != null) {
int windowId =
this.launchIntent.getIntExtra(TiC.INTENT_PROPERTY_WINDOW_ID, TiActivityWindows.INVALID_WINDOW_ID);
if (windowId != TiActivityWindows.INVALID_WINDOW_ID) {
isTiWindowOpen = TiActivityWindows.hasWindow(windowId);
}
}

// If this is the last "Ti.UI.Window" activity, then exit by default unless "exitOnClose" property was set.
boolean exitOnClose = (TiActivityWindows.getWindowCount() <= (isTiWindowOpen ? 1 : 0));
if ((this.window != null) && this.window.hasProperty(TiC.PROPERTY_EXIT_ON_CLOSE)) {
exitOnClose = TiConvert.toBoolean(this.window.getProperty(TiC.PROPERTY_EXIT_ON_CLOSE), exitOnClose);
} else if (this.launchIntent != null) {
exitOnClose = this.launchIntent.getBooleanExtra(TiC.INTENT_PROPERTY_FINISH_ROOT, exitOnClose);
}
return exitOnClose;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -556,16 +556,15 @@ protected void fillIntent(Activity activity, Intent intent)
intent.putExtra(TiC.PROPERTY_EXTEND_SAFE_AREA, value);
}

boolean exitOnClose = false;
if (hasProperty(TiC.PROPERTY_EXIT_ON_CLOSE)) {
exitOnClose = TiConvert.toBoolean(getProperty(TiC.PROPERTY_EXIT_ON_CLOSE), exitOnClose);
} else {
// If launching child activity from Titanium root activity, then have it exit out of the app.
// Use proxy's assigned "exitOnClose" property setting.
boolean exitOnClose = TiConvert.toBoolean(getProperty(TiC.PROPERTY_EXIT_ON_CLOSE), false);
intent.putExtra(TiC.INTENT_PROPERTY_FINISH_ROOT, exitOnClose);
} else if (activity.isTaskRoot() || (activity == TiApplication.getInstance().getRootActivity())) {
// We're opening child activity from Titanium root activity. Have it exit out of app by default.
// Note: If launched via startActivityForResult(), then root activity won't be the task's root.
exitOnClose = activity.isTaskRoot() || (activity == TiApplication.getInstance().getRootActivity());
setProperty(TiC.PROPERTY_EXIT_ON_CLOSE, exitOnClose);
intent.putExtra(TiC.INTENT_PROPERTY_FINISH_ROOT, true);
}
intent.putExtra(TiC.INTENT_PROPERTY_FINISH_ROOT, exitOnClose);

// Set the theme property
if (hasProperty(TiC.PROPERTY_THEME)) {
Expand Down