Webview and HTML5 Database

twodogs

Member
Licensed User
Longtime User
Have a webpage running HTML5 javascript webapp in a webview (with WebViewExtras and WebViewSettings). The webapp writes SQL tables and local storage.

This storage gets cleared at sometime. During Activity_Create with firstTime=true, the database and local storage are gone and the whole webapp resets, not a good user experience.

Is this because the webview process has been cleaned up by Android ? If so, how to stop the cached database from being lost?

I've tried using a WebViewSettings.databasepath of File.DirInternalCache and a directory I made myself in /sdcard, some problem.

Any suggestions!

Thanks
 

twodogs

Member
Licensed User
Longtime User
DOM localstorage is missing, not SQL

Sorry, it's not the SQL database that's missing, it's the DOM localstorage (this contains data that when missing removes my SQL files...)

When webview is re-created, localstorage that was set on last run is no longer found.

eg:

var tno = localStorage.getItem('tno',''); // returns null

Any ideas ?
 
Upvote 0

twodogs

Member
Licensed User
Longtime User
Self Update

Progress...

Checking the cache files, the localStorage data is retained, but is just not read by the webview on restart.

Solution (I hope)....

There is a second webview in this application, it is only used to display logs and so not linked to WebViewExtras and WebViewSettings.

However, applying the same WebViewSettings that are used on the first webview (that was accessing localStorage) onto the second webview, appears to allow the main webview to read localStorage.
 
Upvote 0

clarkke8

New Member
Licensed User
Longtime User
Progress...

Checking the cache files, the localStorage data is retained, but is just not read by the webview on restart.

Solution (I hope)....

There is a second webview in this application, it is only used to display logs and so not linked to WebViewExtras and WebViewSettings.

However, applying the same WebViewSettings that are used on the first webview (that was accessing localStorage) onto the second webview, appears to allow the main webview to read localStorage.

I am having this same problem (localStorage works as long as the app is running, but is not read on restart). I only have the one WebView. I tried adding a second one, making it invisible and calling the same WebViewSettings calls as I do for the first, but it did not fix it. Does your workaround work consistently for you? If so, can you post some sample code?
 
Upvote 0
Top