Skip to content

Commit

Permalink
Merge pull request #8907 from garymathews/TIMOB-24531_6_0_X
Browse files Browse the repository at this point in the history
[6_0_X][TIMOB-24531] Android: Fix exitOnClose behaviour
  • Loading branch information
Lokesh Choudhary committed Mar 24, 2017
2 parents 1422868 + d21020d commit d69edc1
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 d69edc1

Please sign in to comment.