2015-12-04 72 views
1

我在製作Andriod應用程序。當應用程序啓動時,它顯示一個加載頁面,然後顯示一個選擇頁面。我希望當我在我的選擇上按下移動後退按鈕時,它應該從用戶確認「你確定退出應用程序」。 我試試這個代碼,但它不工作Android應用程序中的控制硬件後退按鈕

document.addEventListener("deviceready", onDeviceReady, false); 
document.addEventListener('backbutton', function(event){ 
    event.preventDefault(); // EDIT 
    navigator.app.exitApp(); // exit the app 
}); 
+0

任何一個可以幫助解決這個問題 –

+0

我使用PhoneGap的0.1.11建立我的應用程序。 cordova.js在www/directory .from中缺少我可以獲取此文件的位置。 –

回答

0

I have tried this code and its working.

document.addEventListener("deviceready", onDeviceReady, false); function onDeviceReady() { document.addEventListener("backbutton", onBackKeyDown, false); //Listen to the User clicking on the back button }

function onBackKeyDown(e) { e.preventDefault(); navigator.notification.confirm("Are you sure you want to exit ?", onConfirm, "Confirmation", "Yes,No"); // Prompt the user with the choice }

function onConfirm(button) { if(button==2){//If User selected No, then we just do nothing return; }else{ navigator.app.exitApp();// Otherwise we quit the app. } }

相關問題