The pages are refreshed with:
<meta http-equiv="refresh" content="15">
On closer inspection using 'LOAD_CACHE_ELSE_NETWORK' overides the HTML refresh tag completely so is useless here.
Look at
this screengrab of the webviewCache.db database from an app that loads content from the internet.
I did a test and found that the WebView doesn't cache anything that's loaded with it's LoadHtml method - nothing is added to the webviewCache.db database.
I'd imagine(!) that the
expires column in the cache table dictates when the browser should refresh a page so a page that is not cached is never going to be refreshed.
By the way, i tested with loading local HTML files - using LoadUrl("file:///android_asset/my_page.htm") - and the WebView does not cache these files either.
Unfortunately the HTML string returned is modified. I have a couple of locally stored HTML files for menus in the app. They start off as....
.....<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" height ="100%" id="AutoNumber1">.....
The HTML returned by the JS function has 'height ="100%"' removed and consequently the page appearance changes completely on reorientation.
I thought I could escape the double inverted commas \" within a string literal to replace them or try an octal code \042 instead but neither worked:
html= html.Replace("width=\"100%\"","width=\"100%\" height=\"100%\"")
But that does not seem to work ? Am I missing some Javascript subtlety here?
No.
The HTML table element has no height attribute.
Invalid HTML is not rendered by the browser so isn't part of the rendered page.
The javascript gets the rendered page HTML and
not the original page source.
Are you saying that the WebView renders a table with 100% height when the page is loaded from the server but NOT when it renders HTML passed to it's LoadHtml methods?
An idea i have though...
In the WebView PageFinished Sub query the WebView cache database for the filename of the page that has just been loaded.
Copy that file to File.DirInternalCache and then after an orientation change load that copy of the cached file using LoadUrl().
OR (a faster method maybe?)
Get the filename of the cached file and load it into a process global String variable.
On orientation change load that String using LoadHtml().
Unfortunately neither of these two methods will cause the WebView to cache the reloaded page so your meta refresh isn't going to work.
What you could try is the javascript location.reload() method after reloading the page on orientation change.
https://developer.mozilla.org/en/DOM/window.location
The reload method accepts a single optional Boolean parameter which if True forces a page reload from the server and not the cache.
But i think you'd not want to request a new page each time orientation changes?
Do you have any control over the web pages you are loading?
The pages are presumably created on the fly - or updated every 15 seconds by a script?
Could they be changed so that they use javascript to reload every 15 seconds?
If so then that javascript unlike the meta refresh tag will still work when the page is reloaded on orientation change...
(But not refresh in any browsers that have javascript disabled).
If you have control over the page creation you could simplify things a lot by creating a web service script that returns latest data only (no HTML) to your application in JSON or XML format.
You application (in B4A code not in javascript) could query the web service for updates every 15 seconds and create the HTML to be rendered on the fly - passing it to the WebView LoadHtml method.
As long as your app caches the last received data and keeps a timestamp of the last update then, on orientation change, you can restore the last data and also know when the next update is due.
Martin.