Stop the back button closing app on Android
I'm having real trouble structuring the app to make the windows behave like I describe in this Q.
I'm now trying to go back to basics. Here's a 2 level approach (no tabs, no navGroup). On Android it displays the second level, but hitting the 'Back' button closes the app.
I'm sure the solution is simple, but I've been trying different things for a few hours and haven't gotten anywhere with it :(
app.js
var mainMenu = Ti.UI.createWindow({
backgroundColor:"#fff",
title:"My App"
});
var label = Ti.UI.createLabel({ text: "poke me to open the next window" });
mainMenu.add(label);
label.addEventListener("click", function(e) {
win = Titanium.UI.createWindow({
url:'app-sub1.js',
title:'second'
});
win.open();
});
mainMenu.open();
app-sub1.js
var win2 = Titanium.UI.currentWindow;
var secondView = Titanium.UI.createView({
width:261,
height:178,
top:20
});
var label = Ti.UI.createLabel({ text: "second window" });
secondView.add(label);
win2.add(secondView);
Any ideas?
Thanks in advance,
Matt.
4 Answers
-
Accepted Answer
An Android 'back' will close 'heavyweight' windows. Since you're creating a lightweight window back closes your app instead. Have a search for 'heavyweight' to see previous threads on this topic.
-
Actually, you can capture the back button click. When you do this, it no longer closes the current heavyweight window. See answer here: http://developer.appcelerator.com/question/118993/how-to-fire-androidback-or-simulate-back-button-click
-
You can't add one window to another window, as far as I know (or at least you don't need to). When you call inner_window.open(), doesn't that open the window right on top of win? Then when you call inner_window.close(), it should just close inner_window and leave win in place.
-
modal:true,
exitOnClose: falsethis fixed my problem, Thanks