Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to enable caching in webview android

I want to enable caching in webview android. I am loading an url in webview what I want is when I open the same url again in webview, it should load that url from cache in order to faster loading, how can I achieve this?

like image 727
Prithniraj Nicyone Avatar asked Jan 05 '16 08:01

Prithniraj Nicyone


People also ask

How to store webview as cache in android?

This example demonstrate about How to save cache in local storage of android webview. 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.

Does Webview have cache?

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.

How do you enable cache on android?

In an Android project, open the gradle. properties file and add the following parameters: android. enableBuildCache=true # Set to true or false to enable or disable the build cache.

How do I disable cache in Webview?

Just after creating your webview, before loading any pages, you can clear the cache. myBrowser. clearCache(true) - the boolean indicates if you wish to delete the cached files on disk as well.


1 Answers

You can use the WebView cache to enable caching in WebView.

In the properties of the WebView add the following line:

webView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
like image 107
Maroof Mandal Avatar answered Oct 21 '22 04:10

Maroof Mandal