Skip to content

Commit

Permalink
[TIMOB-24531] Fix exitOnClose behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
Gary Mathews committed Mar 24, 2017
1 parent 1422868 commit 0bd66c6
Showing 1 changed file with 21 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public KrollObject getContext() {
protected static int previousOrientation = -1;
//Storing the activity's dialogs and their persistence
private CopyOnWriteArrayList<DialogWrapper> dialogs = new CopyOnWriteArrayList<DialogWrapper>();
private Stack<TiWindowProxy> windowStack = new Stack<TiWindowProxy>();
private static Stack<TiWindowProxy> windowStack = new Stack<TiWindowProxy>();

public TiWindowProxy lwWindow;
public boolean isResumed = false;
Expand Down Expand Up @@ -857,25 +857,32 @@ public void onBackPressed()
onBackCallback.callAsync(activityProxy.getKrollObject(), new Object[] {});
}
if (topWindow == null || (topWindow != null && !topWindow.hasProperty(TiC.PROPERTY_ON_BACK) && !topWindow.hasListeners(TiC.EVENT_ANDROID_BACK))) {
// no windows to return to
// check Ti.UI.Window.exitOnClose and either
// exit the application or send to background
if (windowStack.size() <= 1) {
if (topWindow != null) {
if (TiConvert.toBoolean(topWindow.getProperty(TiC.PROPERTY_EXIT_ON_CLOSE), true)) {
Log.d(TAG, "onBackPressed: exit");
if (Build.VERSION.SDK_INT >= 16) {
finishAffinity();
} else {
TiApplication.terminateActivityStack();
}
if (topWindow != null) {
boolean exitOnClose = TiConvert.toBoolean(topWindow.getProperty(TiC.PROPERTY_EXIT_ON_CLOSE), false);

// root window should exitOnClose by default
if (windowStack.size() <= 1 && !topWindow.hasProperty(TiC.PROPERTY_EXIT_ON_CLOSE)) {
exitOnClose = true;
}
if (exitOnClose) {
Log.d(TAG, "onBackPressed: exit");
if (Build.VERSION.SDK_INT >= 16) {
finishAffinity();
} else {
Log.d(TAG, "onBackPressed: suspend to background");
this.moveTaskToBack(true);
TiApplication.terminateActivityStack();
}
return;

// root window has exitOnClose set as false, send to background
} else if (windowStack.size() <= 1) {
Log.d(TAG, "onBackPressed: suspend to background");
this.moveTaskToBack(true);
return;
}
}
}
removeWindowFromStack(topWindow);

// If event is not handled by custom callback allow default behavior.
super.onBackPressed();
Expand Down

0 comments on commit 0bd66c6

Please sign in to comment.