简体   繁体   中英

External cache for WebView to load?

I'm using WebView in my application and I need to pre-cache some webpages for later use. Since I want the caching process be less obnoxious, it have to be unnoticeable. So it's better to be implemented in a Service.

I don't know how to achieve this because WebView can only exist in an activity. Is there any method to cache webpages to local storage, and let WebView load it later? Or how can I realize the features with another approach?

Please, read this topic, you should find the answer there, it's explained in details:

http://alex.tapmania.org/2010/11/html5-cache-android-webview.html

As long as the Web pages don't call LocalStorage.clear before they exit the data should be available in a SQLite database.

If my memory is correct is under 4.03 the path is something like /data/data//app_database/localstorage/file__0.localstorage

As the local storage data is saved in a SQLite table called ItemTable you can read this data using the SQLite APIs (when in the same context).

So you could pre-populate the table from your service by inserts into this table.

Sorry to not paste any code - I dont have it with me but this will work - I have done it

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM