Skip to content

Commit

Permalink
fix(android): regression where closing root window from child window …
Browse files Browse the repository at this point in the history
…causes app exit issues as of 8.0.1 (#11093)

- Caused immediate child window to home-out instead of exiting app when closed.
- Caused child window's child to wrongly exit app when closed.

Fixes TIMOB-27177
  • Loading branch information
jquick-axway authored and sgtcoolguy committed Aug 20, 2019
1 parent 7abdbcd commit 57dfc5d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
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

0 comments on commit 57dfc5d

Please sign in to comment.