【问题标题】:Cordova notification exit appCordova 通知退出应用程序
【发布时间】:2015-07-09 06:42:09
【问题描述】:

我有一个应用程序,其中单击返回按钮会提示通知窗口以确认应用程序退出。按钮“是”和“否”效果很好,但是当我点击通知窗口外部时,它会退出应用程序。

代码:

![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.
    }
}][1]

可能是什么错误?

还有什么解决方案可以在多次单击后退按钮时关闭应用程序?

【问题讨论】:

    标签: android jquery ios html cordova


    【解决方案1】:

    onConfirm 更改为

    function onConfirm(button) {
        if(button==1){
            navigator.app.exitApp();
        }
    }
    

    要关闭多个后退按钮,请使用一个计数器,该计数器在按下后递增,并在确认时将其重置,当您按下后退按钮且计数器为 1 或更大时,请致电 navigator.app.exitApp();

    【讨论】:

      猜你喜欢
      • 2017-02-17
      • 1970-01-01
      • 2023-04-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多