简体   繁体   English

最小化Android浏览器Javascript事件

[英]Android browser Javascript events when minimised

I'm building a webapp for Android smartphones that runs with the OS internet browser. 我正在为运行OS互联网浏览器的Android智能手机构建一个Webapp。 the main interface is to input data. 主界面是输入数据。 the data is added to a queue (android 1.5: gears, android 2.x: html5). 数据将添加到队列(Android 1.5:Gears,Android 2.x:html5)。 Each 5 minutes (using setTimeout), the script looks if an internet connection is active, and if so, sends all the queue to the server. 每隔5分钟(使用setTimeout),该脚本将检查Internet连接是否处于活动状态,如果有,则将所有队列发送到服务器。

If the phone is plugged on the wall and the webpage is ontop, the timeout works. 如果电话插在墙上并且网页在顶部,则超时有效。 if the browser is minimized or another application runs on top of it, the timeout doesn't work. 如果将浏览器最小化或在其上运行其他应用程序,则超时不起作用。 if the phone is in sleep mode it doesn't work either. 如果手机处于睡眠模式,则也无法使用。

Can only native apps runs in background? 只能在后台运行本机应用程序吗?

can only native apps runs in background? 本地应用程序只能在后台运行吗?

Certainly, I would not expect the browser to be waking up the device, for your sleep mode scenario. 当然,对于您的睡眠模式情况,我不希望浏览器会唤醒设备。 Apparently, based on your symptoms, they pause all Javascript threads when the browser itself is paused. 显然,根据您的症状,它们会在浏览器本身暂停时暂停所有Javascript线程。 That is not terribly shocking, given the battery problems that leaving those scripts running might cause. 鉴于使这些脚本继续运行可能会导致电池问题,这并不是十分令人震惊。

You could also base it on system time, rather than just setTimeout. 您也可以基于系统时间,而不只是setTimeout。 That way it would at least run when they returned focus to the browser. 这样,至少当他们将焦点返回到浏览器时,它才能运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM