Android - 在应用程序关闭后使 Webview DomStorage 持久化 [英] Android - Making Webview DomStorage persistant after app closed

查看:24
本文介绍了Android - 在应用程序关闭后使 Webview DomStorage 持久化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在开发一个使用 Webview 显示数据的 Android 应用程序时遇到了一个巨大的问题.我在 webview 中使用的网站使用 HTML 5 的 localStorage API.

I'm facing a huge problem developing an Android app which use a Webview to display datas. The website i'm using in the webview use localStorage API of HTML 5.

要启用此功能,我已将 webview 设置如下:

To enable this feature i've set the webview setting like this :

webview.getSettings().setDomStorageEnabled(true);
webview.getSettings().setJavaScriptEnabled(true);

所以 localStorage API 可以工作,但是当我关闭应用程序(并终止进程)时,localStorage 被完全删除,当我重新加载它时,我的所有数据都丢失了.

So the localStorage API works but when I close the app (and kill the process), localStorage is completly erased and when I reload it, all my datas are lost.

我的问题很简单:即使我们关闭应用程序,如何使 Webview 的 DomStorage 持久化?

My question is simple : How to make DomStorage of a Webview persistant even when we close the app ?

感谢您以后的所有回答.

Thank you for all you future answers.

推荐答案

// 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/");

这篇关于Android - 在应用程序关闭后使 Webview DomStorage 持久化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆