background HTML5 WebApps on Android 2.3+

一个人想着一个人 提交于 2019-12-20 03:09:04

问题


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

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

For an example, see http://sandbox.coolaj86.info/html5-audio-tag.html

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.


回答1:


That is done by using background Services.




回答2:


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

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.

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.



来源:https://stackoverflow.com/questions/5331245/background-html5-webapps-on-android-2-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!