I've read about the HTML5 cache manifest, and I've seen Android does support caching websites using the cache manifest. I want to use the cache manifest to download all the required resources for my website to preload it, and then open a WebView and display the remote website using the pre-cached resources. I want to pre-cache my remote page somehow, preferably without using a WebView for the caching process.
The problem with using a WebView for the pre-caching process is that loading the webpage using a WebView renders and executes the page instead of just downloading it.
I've read this: http://alex.tapmania.org/2010/11/html5-cache-android-webview.html, but having a WebView support caching is not what I want. I want the loading process to be instantaneous (assuming the cache manifest / etags of the remote website are the same as the cached version) right after I finish pre-caching the resources, instead of waiting for the WebView to load up and cache everything on the first access.
What is the correct way of pre-caching web pages for viewing later?
Thanks!
You can use the WebView cache to enable caching in WebView.
WebViews are android views, that when created, consume context . And if we cache activity context on the application level, we might end up leaking the activity that was used to create the web-view.
This example demonstrate about How to enable app cache for webview in android. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.
The WebView class is an extension of Android's View class that allows you to display web pages as a part of your activity layout. It does not include any features of a fully developed web browser, such as navigation controls or an address bar. All that WebView does, by default, is show a web page.
What you want to do requires implementing a mechanism for app cache, linked resources, cookies, and local database store for HTML5 apps that use database API, and that's an important part of what browsers do in these days. I don't recommend doing the caching by yourself, not only because it's so much work, but also because I can't recall any method in WebView
and it's friends (WebViewClient
, etc.) that accepts an outside cache.
But your problem has a very simpler solution: you can put a WebView
in your view and set its visibility
to gone
. Then make it visible when it has finished loading the page. WebView
also automatically keeps the cache for your app so that the next time it runs it loads the page more quickly.
For hiding your WebView
and then automatically showing it you just have to override onPageFinished
in WebViewClient.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With