PhoneGap的3.3 / 3.4 - 事件引发的问题的android [英] Phonegap 3.3 / 3.4 - event firing issue android

查看:132
本文介绍了PhoneGap的3.3 / 3.4 - 事件引发的问题的android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我关闭(阅读:发送到后台)的应用程序,暂停不叫,当我重新加载应用程序的简历是不是叫

When I close (read: send to background) the app, the "pause" isn't called and when I reload the app the "resume" isn't called.

在得到这个工作将是极大的AP preciated任何提示!

Any tips on getting this to work would be greatly appreciated!

<script type="text/javascript">
    $(document).ready(function() {
    onLoad();
    });      
</script>   
<script type="text/javascript">
    // Wait for device API libraries to load
    //
    function onLoad() {
        document.addEventListener("deviceready", onDeviceReady, false);
    };

    // device APIs are available
    //
    function onDeviceReady() {
        document.addEventListener("resume", onResume, false);
        document.addEventListener("pause", onPause, false);
        appStartUp();
    };

    // Handle the resume event
    //
    function onResume() {
        setTimeout(function() {
        alert("onResume");
        }, 0);
    };
    // Handle the pause event
    //
    function onPause() {
        setTimeout(function() {
        alert("onPause");
        }, 0);
    };
</script>

好吧,除了这个,应用程序似乎从一开始每次都重新加载,这样的简历和暂停没有做任何事情,因为应用程序被再次加载。

Ok, in addition to this, the app seems to be reloading each time from the start, so the resume and pause don't do anything, as the app is loading again.

我添加机器人:launchMode =singleTask的Andr​​oid清单(通过config.xml中)。但它仍然再次加载。

I've added android:launchMode="singleTask" to the android manifest (via config.xml). But it still loads again.

推荐答案

这并获得成功对我来说杰利贝恩:

This did the trick for me for Jellybean:

它仍然是不工作的奇巧...

It still isn't working for KitKat...

<script type="text/javascript">

document.addEventListener("deviceready", onDeviceReady, false);
document.addEventListener("pause", onPause, false);
document.addEventListener("resume", onResume, false);

function onDeviceReady() {
alert("device ready");
appStartUp();
};

// Handle the resume event
//
function onResume() {
setTimeout(function() {
alert("onResume");
}, 0);
};
// Handle the pause event
//
function onPause() {
setTimeout(function() {
alert("onPause");
}, 0);
};   
</script>

这篇关于PhoneGap的3.3 / 3.4 - 事件引发的问题的android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆