背景HTML5的WebApp在Android 2.3+ [英] background HTML5 WebApps on Android 2.3+

查看:110
本文介绍了背景HTML5的WebApp在Android 2.3+的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

的iOS 4.2+允许特定的web应用在后台运行,没有任何特殊的要求。

iOS 4.2+ allows certain webapps to run in the background, without any special requirements.

这怎么可能运行在Android上后台web应用程序(继续播放音乐,例如)?

How is it possible to run a webapp in the background on Android (to continue playing music, for example)?

有关示例,请参见 http://sandbox.coolaj86.info/html5-audio -tag.html

开始播放音乐的样品在你的iPod / iPad / iPhone的,然后单击背景的应用程序。 双击和滑动由左到右的下级菜单访问播放器控件。

Begin playing the music sample on your iPod/iPad/iPhone, then click to "background" the app. Double click and swipe from left to right in the lower menu to access the player controls.

推荐答案

随着罗比说,要做到这一点,你需要使用一个服务。

As Robby said, to do this you need to use a Service.

显然,你不能有一个后台网页就像你不能有那些与任何浏览器中的一个。该解决方案是使用的WebView的setJavascriptInterface()来创建你的后台服务和HTML5 / JS前端的web视图之间的接口。通过一段JavaScript接口,你可以创建自己的绑定,调用到Java code,从您的JavaScript内。

Obviously you can't have a "background web page" just like you can't have one of those with any browser. The solution is to use WebView's setJavascriptInterface() to create an interface between your background service and HTML5/JS front-end in the WebView. With a javascript interface, you can create your own bindings to call into Java code from inside of your javascript.

可该服务用于preserve后台功能,但是当应用程序回来到的WebView需要通过JavaScript接口再次绑定到它的前景,获得它需要的数据,并填充它的UI。

The service can be used to preserve the background functionality, but when the app comes back into the foreground the WebView needs to bind to it via javascript interface again, get the data it needs, and populate its UI.

这篇关于背景HTML5的WebApp在Android 2.3+的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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