How to remove/close All Windows from Application and open New One

You must Login before you can answer or comment on any questions.

I am using custom Tabs (Buttons) instead of Tabbar, as tabbar can't close on Android and if contain in window so make it irresponsive to close. I am opening all Windows one by one from Bottom Button

function LoadBottomButton() {
 
    var cx = 0;
    for (var i = 1; i <= 5; i++) {
 
            var bottPath = '../images/testEn/' + i + '_en.png';
            var hoverPath = '../images/testEnOrange/' + i + 'oren.png';
            var focusPath = '../images/testSelEn/' + i + 'sel.png'
 
            var bottomBtn = Ti.UI.createButton({
                height:61,
                width:65,
                top: 0,
                backgroundImage:bottPath,
                backgroundFocusedImage:hoverPath,
                backgroundSelectedImage:focusPath,
                zIndex: 2,
                left:cx,
                tag:i,
 
            });
 
 
            if (i == 1) { 
                bottomBtn.backgroundImage = focusPath;
            }
 
            bottomBtn.addEventListener('click',function(e) {
 
 
                if (e.source.tag == 2) {
 
                    //alert(e.source.tag);
                        var winCat1 = null;
                            winCat1 = Titanium.UI.createWindow({
                                url: 'business.js',
                                // title: e.source.catName,
                                backgroundImage: '../images/bkg-complete.png',
                                barColor:'#111',
                                backgroundColor: 'transparent',
                                tabBarHidden: true,
                                //modal: true,
                                navbarHidden:true,
                                fullscreen:true,
                                exitOnClose:true
                            });
 
                            winCat1.orientationModes = [
                                Titanium.UI.PORTRAIT
                            ];
 
                            winCat1.open();
 
                            //win1.close();
                } else if (e.source.tag == 3) {
 
                    var winCat2 = null;
                    winCat2 = Titanium.UI.createWindow({
                                url: 'favorites.js',
                                // title: e.source.catName,
                                backgroundImage: '../images/bkg-complete.png',
                                barColor:'#111',
                                backgroundColor: 'transparent',
                                tabBarHidden: true,
                                //modal: true,
                                navbarHidden:true,
                                fullscreen:true,
                                exitOnClose:true
                            });
 
                            winCat2.orientationModes = [
                                Titanium.UI.PORTRAIT
                            ];
 
                            winCat2.open();
 
                } else if (e.source.tag == 4) {
 
                    var winCat3 = null;
                    winCat3 = Titanium.UI.createWindow({
                                url: 'mapview_update.js',
                                // title: e.source.catName,
                                backgroundImage: '../images/bkg-complete.png',
                                barColor:'#111',
                                backgroundColor: 'transparent',
                                tabBarHidden: true,
                                //modal: true,
                                navbarHidden:true,
                                fullscreen:true,
                                exitOnClose:true
                            });
 
                            winCat3.orientationModes = [
                                Titanium.UI.PORTRAIT
                            ];
 
                            winCat3.open();
                } else if (e.source.tag == 5) {
 
                    var winCat4 = null;
                    winCat4 = Titanium.UI.createWindow({
                                url: 'update.js',
                                // title: e.source.catName,
                                backgroundImage: '../images/bkg-complete.png',
                                barColor:'#111',
                                backgroundColor: 'transparent',
                                exitOnClose:true,
                                tabBarHidden: true,
                                //modal: true,
                                navbarHidden:true,
                                fullscreen:true,
                            });
 
                            winCat4.orientationModes = [
                                Titanium.UI.PORTRAIT
                            ];
 
                            winCat4.open();
                } 
                else if (e.source.tag != 1) {
                    win1.close();
                    win1 = null;
                }
 
            });
            win1.add(bottomBtn);
 
            cx = cx + 65;
 
    }
 
}
Bottom Buttons are working fine but When I close but when I close win1 to open new Window
buttn.addEventListener('click', function(e) {
 
    //var activity = Titanium.Android.currentActivity;
        //activity.finish();
 
    var winAr1 = Ti.UI.createWindow({
            width:'auto',
            height:'auto',
            top:0,
            left:0,
            backgroundImage: '../images/bkg-complete.png',
            url:'ui/home_ar.js',
            tabBarHidden: true,
                //modal: true,
                navbarHidden:true,
                fullscreen:true,
            exitOnClose:true
        });
 
        winAr1.orientationModes = [
            Titanium.UI.PORTRAIT,
        ];
        winAr1.open();
 
    win1.close();
    win1 = null;
 
});
win1 is not releasing and removing completely and some content remain on stack and usually its also called focus of same win1 rather removing from stack and also navigate me to last winCat1 - 4 which was opened before. Therefore how to check which ever Windows are present on stack so can remove/ close from the memory to open new layout in Android. This is I am doing only because TabGroup and Tabbar doesnt remove in Android.

It works perfect for first time when LoadBottomButton() isnot called, only buttn.addEventListener is called but not after the method is called

2 Answers

the best solution is to keep track of all of the windows yourself and clean them up yourself, consider a global variable of window objects

I agree with the above. I've implemented a solution found on a page that follows the patter below.

var globals = {};
function createGlobal(key,obj){
globals[key] = obj;
}
function findGlobal(key){
return globals[key];
}
Then in my application when I create a window I want to manage later I do the following
// if _win is my window object
createGlobal('coolWindow', _win);
 
// Now I can get that window whenever and wherever I want with this
var _windowToClose = findGlobal('coolWindow');
_windowToClose.close();
This way you don't see a bunch of globally scoped variables, just a couple of functions to access anything you want.

Your Answer

Think you can help? Login to answer this question!