【发布时间】:2018-01-19 08:40:45
【问题描述】:
当我按下我的 Android 设备上的返回按钮时,它会关闭我当前正在进行的活动。我需要防止这种情况发生。我找到了this 问题在这里,我还找到了该事件的this 文档并且命名不同,然后我找到了同一事件的第三个名称here。我尝试了所有这些,即使同时像这样:
$.currentWindow.addEventListener("android:back",back);
$.currentWindow.addEventListener("androidback",back);
$.currentWindow.addEventListener("windows:back",back);
$.currentWindow.addEventListener("windowsback",back);
它们都不起作用,我也注意到我必须使用 Titanium.UI.currentWindow.addEventListener("evt", callback) 但 Titanium.UI.currentWindow 似乎是未定义。我这样打开我的窗口:
var nextWindow = core.createWindow({
controllerName : "restaurantActivity"
});
nextWindow.open();
这是我的回调函数
function back(e) {
e.cancelBubble = true;
console.log(e.type);
if (Ti.App.pplatillo.length != 0) {
console.log("Confirm before exit.");
var dialog = Ti.UI.createAlertDialog({
cancel : 1,
buttonNames : ["Sí", "No"],
message : "Tienes artículos en tu carrito y el pedido no se ha concretado, si sales perderás los artículos. ¿Seguro que desea salir?",
title : "Salir"
});
dialog.addEventListener("click", function(e) {
if (e.index != e.source.cancel) {
Ti.App.pplatillo = [];
Ti.App.car = 0;
Ti.App.totalBill = 0;
$.window.close();
}
});
dialog.show();
} else {
console.log("Just exit :(");
$.window.close();
}
}
任何帮助将不胜感激。
【问题讨论】:
标签: javascript android titanium appcelerator back