I am working on hybrid app and wanted to know the best practices or good way of architecting/structuring the application.

Should one use one webview per activity or should have one single activity with one just webview and change the html pages that are being loaded?

Can one use one webview on multiple activities?

Certain web pages requires loading of heavy resources such as videoview. Due to this I was thinking of using single webview with different activities if its feasible.

有帮助吗?

解决方案

You should go with Single Activity with Single Webview. Wherein load the static resources (Html files , js files images etc. )from local location and go to server for dynamic data.

Call for data from server better to use native layer to avoid cross scripting issue. Having said that , Write all the API's in Java and call each api from WebView either using JavaScriptInterface Mechanism or using ShouldOverrideURL method of webview. Recommended is JavaScriptInterface.

To your answer for question : Its always feasible having one webview with multiple activities. but that's not recommended. One Activity is more than enough to take care of loading complete website with different pages in webview.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top