您的解决方案是设置此属性: @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;
});