您的位置:首页 > 移动开发 > Android开发

sencha touch中处理Android返回按钮事件

2016-02-18 17:08 447 查看
应用中只有一个NavigationView的情况: 
// 处理一下android返回按钮
document.addEventListener("deviceready", onDeviceReady, false);

function onDeviceReady() {
document.addEventListener("backbutton", onBackKeyDown, false);
}

function onBackKeyDown() {
var canPop = false;
var id = Ext.Viewport.getActiveItem().id;
if (id.indexOf("login") != -1) {
} else if (id.indexOf("mainview") != -1) {
var mainview = Ext.Viewport.getActiveItem();
var length = mainview.getItems().length;
if (length > 2) {
canPop = true;
}
}
if (canPop) {
console.log("canPop");
ChinaFertilizer.app.getController("MainController").pop(1);
} else {
Ext.Msg.confirm("提示", "您确定要退出应用吗?", function(e) {
if (e == "yes") {
navigator.app.exitApp();
}
}, this);
}

}

在Ext.tab.Panel下有多个NavigationView的情况: 
// 处理一下android返回按钮
document.addEventListener("deviceready", onDeviceReady, false);

function onDeviceReady() {
document.addEventListener("backbutton", onBackKeyDown, false);
}

function onBackKeyDown() {
var item = Ext.Viewport.getActiveItem();
var id = item.id;
if (id.indexOf("mainView") != -1) {
<
4000
span class="indent">     var mainview = Ext.Viewport.getActiveItem();
//				 var mainview = Ext.getCmp('moreView').getActiveItem();
var length = mainview.getActiveItem().getItems().length;
console.log("length = " + length);
if(length > 2){
if(app.viewId == 0){
app.getController("phone.MyAppControllerP").pop(1);
}else if(app.viewId == 1){
app.getController("phone.TodoControllerP").pop(1);
}else if(app.viewId == 2){
app.getController("phone.AppCenterControllerP").pop(1);
}else if(app.viewId ==3){
app.getController("phone.MoreControllerP").pop(1);
}
}else{
if (typeof WL === 'undefined') {
Ext.Msg.confirm("提示", "您确定要退出应用吗?", function(e) {
if (e == "yes") {
navigator.app.exitApp();
}
}, this);
} else {
WL.SimpleDialog.show("提示", "您确定要退出应用吗?", [ {
text : "确定",
handler : function() {
navigator.app.exitApp();
}
}, {
text : "取消",
handler : function() {
}
} ]);
}

}
}else{
if (typeof WL === 'undefined') {
Ext.Msg.confirm("提示", "您确定要退出应用吗?", function(e) {
if (e == "yes") {
navigator.app.exitApp();
}
}, this);
} else {
WL.SimpleDialog.show("提示", "您确定要退出应用吗?", [ {
text : "确定",
handler : function() {
navigator.app.exitApp();
}
}, {
text : "取消",
handler : function() {
}
} ]);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: