uniapp打包成apk,监听安卓手机的返回键
有时候在某个页面的时候需要监听如果用户按了两次按钮则直接退出
onBackPress(e){
// console.log("监听返回123", e)
let _this = this;
// 这个backbutton是你点击了返回键
if(e.from === 'backbutton'){
// 这里使用backCount来记录按了多少次按钮,放在这个组件的data里面就行了
this.backCount++;
if (this.backCount > 1) {
plus.runtime.quit();
} else {
plus.nativeUI.toast('再按一次退出应用');
}
setTimeout(function() {
// console.log("这里", _this.backButtonPress);
_this.backCount = 0;
}, 1000);
// 这里返回true是阻值页面跳转
return true;
}
}