0

每个人

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

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

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

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

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

谁能帮帮我,谢谢。

4

2 回答 2

1

在 index.js 中使用这个

$.index.exitOnClose = 假

于 2016-05-26T23:21:25.910 回答
0

您的解决方案是设置此属性: @genocsb 回答的exitOnClose = false。它仅在 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;
});
于 2016-06-06T11:03:35.127 回答