jack
jack

Reputation: 98

appcelerator how close the window of index from another window

everyone

I am using titanium with alloy, I have two windows which are index.js and main.js.

The window of index.js will be opened when the app run, there is a button in index, main will be opened if someone click the button. Main have another button which is used to close the index.

As you see, I am trying to close index window in main window.

Everything works fine in IOS, but when I test it in Android, I found a strange problem: when I click the button in main.js to close index window, all windows(both of index and main) are closed.

I tried many methods, like use Ti.APP.trigger/Ti.APP.addEventListener and send $.index or a callback function to main.js.

Could anyone help me, thanks.

Upvotes: 0

Views: 557

Answers (2)

Prashant Saini
Prashant Saini

Reputation: 3539

Your solution is to set this property : exitOnClose = false as answered by @genocsb. It's available only on Android.

Actually, this property tells that which window should close the app upon closing the window itself. So, by default, the very first window has the its property exitOnClose = true.

In your case, do something like this:

- index.js

Alloy.Globals.Index = $.index;
Alloy.Globals.Index.open();

// If you will do this and press back button on index screen, then you will land to splash screen.
// Alloy.Globals.Index.exitOnClose = false;

- main.js

$.button.addEventListener('click', function (){
    $.main.exitOnClose = true;                  // setting it to true will cause your app to close from main.xml screen on back button press
    Alloy.Globals.Index.exitOnClose = false;    // setting it to false here will ensure that you will not land to splash screen if back button is pressed.
    Alloy.Globals.Index.close();
    Alloy.Globals.Index = null;
});

Upvotes: 0

Said CHAOUCHE
Said CHAOUCHE

Reputation: 695

in index.js use this

$.index.exitOnClose = false

Upvotes: 1

Related Questions