PhoneGap的不断的onPause之后运行在Android上

PhoneGap的不断的onPause之后运行在Android上

本文介绍了PhoneGap的不断的onPause之后运行在Android上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我决定来测试是否PhoneGap的的WebView是活的,当应用程序是在后台。

I decided to test if phonegap WebView is live when app is in a background.

function test2(x){
    $('<div></div>', {text: x.cmd}).appendTo($('#list'));
}
$(function(){test2({cmd:"start"});});
function cb_pause(){test2({cmd:"pause"});}
function cb_resume(){   test2({cmd:"resume"});}
function tick(){test2({cmd:"timer" + timer});timer++;setTimeout(tick, 1000);}
document.addEventListener("pause", cb_pause, false);
document.addEventListener("resume", cb_resume, false);
tick();

它打印暂停恢复的onPause onResume 。和打印 TIMER0 定时器等每一秒。

It prints pause and resume on onPause and onResume.and print timer0, timer1, etc every second.

当我离开应用程序,并开始玩游戏它打印偶数。我知道我可以和应该停止定时器的onPause ,但仍。它看起来是错误的。我预计Android将冻结的WebView。

It was printing even when I left app and started playing game.I know I can and should stop timer in onPause but still. It looks wrong. I expected android will freeze WebView.

我知道后台线程会如果后台程序,直到它被卸载不会停止。

I know background thread will not stop if in background app until it is unloaded.

所以,问题是:有没有办法冻结的onPause /暂停/卸载的WebView和解冻对 onResume

So question is: Is there way to freeze/suspend/unload webview on onPause and unfreeze/resume/load on onResume

当我说的负荷我的意思是应该在相同的状态,当用户离开应用程序。

When I say load I mean it should be in same state when user left app.

当我说的冻结,我的意思是我的code,以将暂停,即使它会继续调用的setTimeout

When I say freeze, I mean that my code to will pause even when it will continue to call setTimeout

我想我期待的Andr​​oid的行为类似于iOS的。

I guess I expect Android to behave like iOS.

推荐答案

我迟到与响应。在PhoneGap的有 keepRunning 参数在的config.xml

I am late with response. In phonegap there is keepRunning param in config.xml

您必须添加以下代码行的config.xml

You must add following line to config.xml

<preference name="keepRunning" value="false" />

这将调用 pauseTimers()并暂停所有WebViews。 pauseTimers()不是隐藏方法和无反射是必要的。

It will call pauseTimers() and pause all WebViews. pauseTimers() is not hidden method and no reflection is needed.

这篇关于PhoneGap的不断的onPause之后运行在Android上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-02 01:25