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();
It prints pause
and resume
on onPause
and onResume
.
and print timer0
, timer1
, etc every second.
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.
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.
When I say freeze, I mean that my code to will pause even when it will continue to call setTimeout
I guess I expect Android to behave like iOS.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…