I am trying to open a new window and close its parent window, so that I can't return to previous window and keep the application more efficient.
However calling close on parent window causes the new window to be closed as well, regardless if I call it before opening the new window or after. What happens is new window is being opened and then closed right away. I tried to open a new window on the event listener close for parent window... but that doesn't help.
Code example:
`app.js:`
var loginWin = Ti.UI.createWindow({
url:login.js
});
loginWin.open();
`login.js:`
var win = Ti.UI.currentWindow;
var btn = Ti.UI.createButton({.....});
btn.addEventListener('click',function(e){
//putting win.close() also causes the problem
var appCoreWindow = Ti.UI.createWindow({
url:"core.js"
});
win.close();
appCoreWidnow.open();
});
win.add(btn);
You are creating Window object inside eventhandler and when function finishes garbage collector removes all local variables from it, including appCoreWindow.
Try this instead:
var win = Ti.UI.currentWindow;
var appCoreWindow = Ti.UI.createWindow({ url:"core.js" });
var btn = Ti.UI.createButton({.....});
btn.addEventListener('click',function(e){
appCoreWidnow.open();
win.close();
});
win.add(btn);