I am writing an app where the user is present with a list of URLs. To make it appear more faster, I want to detect the Wi-Fi state and load the URLs in the background, so when the user picks a URL, they are quickly presented the data specially when they are connected to Wi-Fi. Is there a way I can do this?
1 Answer
Yes, using shouldInterceptRequest. Which you can use to detect if you have a cached version of the requested URL and return an input stream to the cache which the WebView will use instead of loading it from ze webz
For versions before honeycomb, it might be possible to use shouldOverrideUrlLoading, calling webview.loadData(datafromcache, "text/html", "UTF-8"); and return true.
3 Comments
prat
is there any code snippet which relates to cache ?
FunkTheMonk
things have changed in the last 12 years, now its probably better to have trigger retrofit to pre-load the urls and then it'll have them cached (if configured) for later
prat
thanks, my project is 10 years old so need to adapt accordingly. If any leads, let me know