科尔多瓦:暂停事件不触发 [英] Cordova: Pause event not firing

查看:180
本文介绍了科尔多瓦:暂停事件不触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于某种原因暂停事件不会当它应该烧。

如果我preSS我的手机上的主页按钮,这就是暂停事件应该被解雇,应暂停音乐。而是它不断播放。

但是,当我再次打开我的应用程序是突然顿住,然后重新开始。因此,它激发两个事件,当我返回到应用程序。

为什么不的onPause当我离开应用程序启用?

我有以下的code:

 函数的onLoad(){
    document.addEventListener(deviceready,onDeviceReady,FALSE);功能onDeviceReady(){
    document.addEventListener(恢复,onResume,FALSE);
    document.addEventListener(暂停,在onPause,FALSE);
}起作用的onPause(){
    PauseMusic();
    警报('暂停');
}功能onResume(){
    ResumeMusic();
    警报('恢复');
}


解决方案

我觉得我有你的相同问题。我已经设定的PhoneGap的config.xml变量KeepRunning为false。我设置为true,现在它时,它应该得到暂停事件。这里是我在谈论的config.xml行:

 < preference NAME =KeepRunningVALUE =真/>

我想这是有道理的,如果应用程序没有那么运行,直到应用程序再次运行暂停事件code不会得到运行。我想KeepRunning比听暂停事件更高的优先级。要得到适当的解释,为什么这正是在一个较低的水平这将是有趣。

For some reason the pause event is not firing when it should.

If I press the home button on my phone, this is where the pause event should be fired, which should pause the music. But instead it keeps on playing it.

But when I open my app again it is suddenly paused and then resumed. So it fires both events when I return to the app.

Why is onPause not firing when I leave the app?

I have the following code:

function onLoad() {
    document.addEventListener("deviceready", onDeviceReady, false);

function onDeviceReady() {
    document.addEventListener("resume", onResume, false);
    document.addEventListener("pause", onPause, false);
}

function onPause() {
    PauseMusic();
    alert('paused');
}

function onResume() {
    ResumeMusic();
    alert('resumed');
}

解决方案

I think I had your exact same problem. I had set the Phonegap config.xml variable KeepRunning to false. I set to true and now it gets the pause event when it is supposed to. Here is the config.xml line I am talking about:

<preference name="KeepRunning" value="true"/>

I suppose it makes sense that if the app is not running then the pause event code won't get run until the app runs again. I guess KeepRunning has higher priority than listening to pause event. It would be interesting to get a proper explanation as to why this is exactly at a lower level.

这篇关于科尔多瓦:暂停事件不触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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