appcelerator如何从另一个窗口关闭索引窗口

时间:2016-05-26 14:59:40

标签: titanium appcelerator titanium-mobile titanium-android

大家

我使用合金钛,我有两个窗口是index.js和main.js。

当app运行时,index.js的窗口将被打开,索引中有一个按钮,如果有人点击按钮,将打开main。 Main有另一个按钮,用于关闭索引。

如您所见,我正在尝试关闭主窗口中的索引窗口。

在IOS中一切正常,但是当我在Android中测试时,我发现了一个奇怪的问题:当我点击main.js中的按钮来关闭索引窗口时,所有窗口(索引和主窗口)都被关闭。

我尝试了很多方法,比如使用Ti.APP.trigger / Ti.APP.addEventListener并将$ .index或回调函数发送到main.js.

任何人都可以帮助我,谢谢。

2 个答案:

答案 0 :(得分:1)

index.js中的

使用此

  

$ .index.exitOnClose = false

答案 1 :(得分:0)

您的解决方案是设置此属性: exitOnClose = false ,由@genocsb回答。它仅适用于Android。

实际上,此属性告诉关闭窗口本身应关闭应用程序的窗口。因此,默认情况下,第一个窗口的属性为 exitOnClose = true

在你的情况下,做这样的事情:

- 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;
});
相关问题