[TIMOB-26213] Android: Backing out of root window with exitOnClose false shows splash if child window closed programmatically
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Critical |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2018-08-06T23:28:19.000+0000 |
Affected Version/s | Release 6.0.4 |
Fix Version/s | Release 7.2.1 |
Components | Android |
Labels | android, exitonclose, window |
Reporter | Michael Gangolf |
Assignee | Gary Mathews |
Created | 2018-07-14T15:44:40.000+0000 |
Updated | 2018-08-08T21:36:07.000+0000 |
Description
I want to use
exitOnClose:false
on my root window, so it will go into background and is not exiting. It works fine unless I close a child window with the homeAsUp
back arrow.
*Example:*
var win = Ti.UI.createWindow({backgroundColor: "#fff",exitOnClose: false});
var btn = Ti.UI.createButton({title: 'open'});
btn.addEventListener('click', function() {
var win2 = Ti.UI.createWindow({backgroundColor: "#fff"});
var actionBar;
win2.addEventListener("open", function() {
if (Ti.Platform.osname === "android") {
if (win2.activity) {
actionBar = win2.activity.actionBar;
if (actionBar) {
actionBar.displayHomeAsUp = true;
actionBar.onHomeIconItemSelected = function() {win2.close();};
}
}
}
});
win2.open();
});
win.add(btn);
win.open();
*Example video:* https://migaweb.de/open_window.mp4
*Steps to reproduce*
* First three times I open the index and close it and open it again (was in background, seeing no splashscreen -> works fine)
* After that I open the second window two time and close it with the back button and then the index window, too (same, works fine)
* Last time I close the second window with the homeAsUp button and I end up at the splashscreen when I close the index. After that I ALWAYS end up at the splashscreen unless I kill the app
*Tested versions:*
Android 7
HTC A9
Ti SDK 7.2.0.GA, 7.3.0.v20180711185043
*Expected behaviour*
Always go to background and don't show the splashscreen when exitOnClose
is set to false on the root window.
I can validate the issue in Android 8.1.0 device with SDK 7.2.0.GA. I was able to reproduce the behavior described. Moving to engineering.
This is not a bug. This is the correct behavior. The root activity is the splashscreen. That root activity also hosts Titanium's JavaScript runtime. The 1st window you create in Titanium is actually the 2nd activity that gets created and is a child activity window on top of the activity hosting the splashscreen image. When
exitOnClose
is set totrue
(the default) on the 1st window you create, Titanium will automatically close the root splashscreen activity when your 1st window is closed. Setting it tofalse
prevents this behavior and the Android OS will navigate back to the root splash activity. If you want the app to be backgrounded instead, then you should override the back button and do a home button equivalent like the below. This effectively makes your app behave like iOS and prevents it from closing.Does this help?
But why does this only happen, when you close the 2nd window with the
homeAsUp
button and not when you just close the button with the back button? It's not consistent that it will go to the splash screen. It actually goes to background when you open the app and click the system back arrow and won't show the splashscreen (the first try in the video). -I've tested the intent version before but I think it had a different bug. I'll test that again!- The intent version looks correct in the demo app. I'll check it inside the full app to see where the problem was. Might be some implementationI'm not sure what you mean. The
displayHomeAsUp
is an Android feature intended to go to a root window of your choosing. It's not designed to take you to the Android OS home screen, although you can rig it to do that via the intent I showed you up above. https://developer.android.com/training/implementing-navigation/ancestral But what I said is definitely true. The root activity window is the splash screen. This is what hosts your JS code. Once that root splash activity gets destroyed, it'll also terminate the JS runtime. So, they key to keep it running is to prevent it from being destroyed. And the only known way that I know of is to override the back key and do a home button press equivalent as I've shown you.Hmm... looks like I wasn't fully aware of how are
exitOnClose
feature completely works. Sorry about that. Yes, this does look like a bug. OurexitOnClose
supports 2 bits of functionality when setfalse
:If you call
Window.close()
, it will close the window (correct behavior) and takes you back to the root splash screen window instead of exiting the app. _(This is the feature I mentioned above.)_If you press the Back button, it'll background the app instead of closing the window. _(I wasn't aware of this feature.)_
The 2 behaviors I've mentioned above can be seen with the following code.The issue you've mentioned happens when calling a 2nd window's
close()
method which can be reproduced with the below...I suspect this is an issue with our
TiBaseActivity.onBackPressed()
method looking at the top-most activity's proxy settings instead of its own. https://github.com/appcelerator/titanium_mobile/blob/master/android/titanium/src/java/org/appcelerator/titanium/TiBaseActivity.java#L843Is this related to TIMOB-26269?
[~hknoechel], no. This ticket is a different issue. The issue here is if you programmatically close a child window, then "exitiOnClose" set to
false
no longer works. _Edit: Actually, let me double check with the other person in [TIMOB-26269]. I may be misinterpreting the issue he's running into._[~michael], I can't reproduce this issue anymore with our latest changes to "master" and "7_3_X" branches. It looks like [~gmathews] has inadvertently fixed this with his changes to the window/memory handling here... https://github.com/appcelerator/titanium_mobile/commit/4a76b6f0922ffd90ea9628da174c99210b9c171a#diff-034a9360d01584987d9c951c0a215f65 We were missing a
removeWindowFromStack()
call in our Activity'sonDestroy()
method, which would happen if we closed the activity programmatically. So, the issue was that ouronBackPressed()
code was picking up the destroyed child window proxy that was still in the stack instead of the root window's proxy and the child window proxy did not have the "exitOnClose" property set. I guess this means Gary gets 2 points on Slack, eh? Don't spend them point all in one place now. :)*Side Note:* I've confirmed that this issue was introduced as of Titanium 6.0.4.
Awesome! Works fine here, too. 7.3.0 is a great version!
Verified works with SDK 7.3.0.v20180807095741 & 7.2.1.v20180726150551. Closing.