Android Question Pre-loading a webview

Martin Larsen

Active Member
Licensed User
Longtime User
I would like to speed up the loading of a webview that almost always (like in 90% of the times) will be loaded by the user. So it makes sense to pre-load the content upfront, for example in the main activity.

One feasible way would be to load the URL in the main activity or starter service and save the html in a global variable.

Later on, in the activity where the webview is going to be shown, it could then be loaded with the saved html.

Is the above strategy OK or is there a better way?

Ideally it should work also in B4i.
 

Martin Larsen

Active Member
Licensed User
Longtime User
You can load the page with an invisible WebView and show the WebView when needed.

That was actually my first thought, but I couldn't make it work.

I have a main activity A and a second activity B. I would like to load the page in the start-up phase, eg. in A's Activity_Create. When B is started, the webview should be ready right away.

How do I load the webview before its parent activity is shown?
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
I have a main activity A and a second activity B. I would like to load the page in the start-up phase, eg. in A's Activity_Create. When B is started, the webview should be ready right away.
it is not possible. You can load the html and put it into a global variable.
When you start a new activity you have to initialize a new webview here in activity_create.
No one stops you to load the already known html here.
 
Upvote 0

Martin Larsen

Active Member
Licensed User
Longtime User
No one stops you to load the already known html here.

That was my idea in #1. But as Erel rightly noted, there are lots of resources like images, js, and css which will not be pre-loaded. Then he suggested using an invisible webview. I am wondering how to do this.
 
Upvote 0
Top