background HTML5 WebApps on Android 2.3+

前端 未结 3 1609
南方客
南方客 2021-01-22 01:03

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 p

3条回答
  •  半阙折子戏
    2021-01-22 02:05

    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.

提交回复
热议问题