【问题标题】:appcelerator how close the window of index from another windowappcelerator 如何从另一个窗口关闭索引窗口
【发布时间】:2016-09-24 16:11:05
【问题描述】:
大家
我使用的是钛合金,我有两个窗口,分别是 index.js 和 main.js。
应用运行时会打开index.js的窗口,index中有一个按钮,如果有人点击按钮就会打开main。 Main 有另一个按钮,用于关闭索引。
如您所见,我正在尝试关闭主窗口中的索引窗口。
在 IOS 中一切正常,但是在 Android 中测试时,我发现了一个奇怪的问题:当我单击 main.js 中的按钮关闭索引窗口时,所有窗口(包括索引和主窗口)都关闭了。
我尝试了很多方法,例如使用 Ti.APP.trigger/Ti.APP.addEventListener 并将 $.index 或回调函数发送到 main.js。
谁能帮帮我,谢谢。
【问题讨论】:
标签:
titanium
appcelerator
titanium-mobile
titanium-android
【解决方案1】:
在 index.js 中使用这个
$.index.exitOnClose = false
【解决方案2】:
您的解决方案是设置此属性: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;
});