Android - Making Webview DomStorage persistant after app closed

江枫思渺然 提交于 2019-11-27 20:06:35

Did you set the DatabasePath? Android doesn't know where to save the DOMDatabase by default, if you don't set it calling

webview.getSettings().setDatabasePath()
ozmike
// Confimed on android 2.1 emulator
// enable javascript localStorage

WebSettings webSettings = myWebView.getSettings();
webSettings.setDomStorageEnabled(true);   // localStorage

// e.g., if your package is www.myapp.whatever;
webSettings.setDatabasePath("/data/data/www.myapp.whatever/databases/");

You must enable the database as well as setting its path:

webview.getSettings().setDatabaseEnabled(true);
webview.getSettings().setDatabasePath();
webSettings.setDomStorageEnabled(true);

The first line caught me out for quite a while...

The above post is mixing two diferent concepts:

To make your data persist after the session is closed make sure you are not using (on your javascript) sessionStorage

DOMStorage and database storage are two different things. Database storage is not part of HTML5: http://www.tutorialspoint.com/html5/html5_web_sql.htm

DOMStorage is more related to HTML5 and includes session storage, which -by design- will disappear when you close your browser. You will find more hits via searching "local storage' that 'DOM storage'.

http://viralpatel.net/blogs/introduction-html5-domstorage-api-example/

Thus, to enable DOMstorage you just need this: webSettings.setDomStorageEnabled(true);

Lisarien

This issue was answered in this post with an update for Android v4.1.1.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!