uniapp打包成apk,監聽安卓手機的返回鍵

小園子1346513發表於2020-12-23

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;
		}
	}

相關文章