android - 如何通过覆盖 BackButton 使我的 PhoneGap android 应用程序暂停?

标签 android plugins cordova onpause localnotification

我正在尝试使用 phonegap 和 LocalNotification 插件开发一个 android 应用程序。 我想在 onPause 中运行我的应用程序, 在我的 index.html 上

document.addEventListener("pause", onPause, false);

函数 onPause() { //处理暂停事件

setInterval( function() {
    Ext.data.JsonP.request({
            url: 'http://convert4mobile.net/backend/API/qr/push.php',
            callbackKey: 'callback',
            success: function(data)
            {

                if(data.success == true)
                {
                    if (typeof plugins !== "undefined") {
              window.plugins.localNotification.add({
                        date : new Date(),
                        message : data.time+"\r\n"+data.msg,
                        ticker : "A new code was generated",
                        repeatDaily : false,
                        id : 4
                });
                }
                }
            }
           });
} , 2000);

当通过主页按钮/结束通话按钮关闭/最小化应用程序时,它工作正常。 我想通过点击 BackButton 来做同样的事情。 有什么想法吗??

最佳答案

在此方法中输入您想要的任何代码:

@Override
public void onBackPressed() {
    // TODO Auto-generated method stub
    super.onBackPressed();
}

教程在这里:http://chrisrisner.com/31-Days-of-Android--Day-10%E2%80%93The-Back-Button

关于android - 如何通过覆盖 BackButton 使我的 PhoneGap android 应用程序暂停?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11297763/

相关文章:

android - 无法在 CLI 上从 Git 安装 Cordova 插件

wordpress - 我的 WordPress 网站中的 "Endurance Cache"功能是什么?

java - 如何在我自己的插件中使用 IntelliJ IDEA 编辑器?

android - 错误 : An error occured during creation of android sub-project

android - 从数据类连接 Kotlin 中的字符串数组

java - NoClassDefFoundError : android. support.v4.util.ArrayMap

java - 动态绘制立方体的问题

android - Android NDK 暂停/恢复中的 hello-gl2 示例是否正确?

javascript - jQuery ajax 调用变量

javascript - Android 不安全 :tel: with phonegap application