To clear cache in an Android WebView, call webView.clearCache(true) on the main thread. The true argument removes the files cached on disk as well as the RAM cache. That call only clears the resource cache, so cookies, localStorage and the back history each need their own call.
Most people looking for this have one real problem: they changed their website and the app still shows the old version.
What clearCache actually clears in an Android WebView
clearCache removes the WebView’s resource cache, meaning stored copies of pages, scripts, stylesheets and images. The WebView reference describes it as clearing “the resource cache” and notes that the cache is per-application. Calling it on one WebView clears the cache for every WebView in your app.
The boolean matters. With false, only the RAM cache is cleared. With true, disk files go too.
// Run on the main thread, the one that created the WebView
webView.clearCache(true)
webView.reload()
A real case: you push a new style.css to your site, the HTML updates in the app, but the old colours remain. That’s a cached stylesheet, and clearCache(true) followed by reload() fixes it.
Which call clears which kind of data
Each type of stored data in a WebView has a separate API. Pick the row that matches your symptom.
| Stored data | Call that clears it | Notes |
|---|---|---|
| Cached pages, CSS, JS, images | webView.clearCache(true) |
Per-app, all WebViews |
| Cookies and login sessions | CookieManager.getInstance().removeAllCookies(null) |
Asynchronous |
| localStorage and Web SQL | WebStorage.getInstance().deleteAllData() |
All JavaScript storage |
| Back/forward list | webView.clearHistory() |
Per WebView |
| Remembered SSL error choices | webView.clearSslPreferences() |
Rarely needed |
The CookieManager reference says removeAllCookies is asynchronous, and the callback value tells you whether any cookies were removed. The older removeAllCookie() was deprecated in API level 21.
WebStorage’s deleteAllData() wipes everything the JavaScript storage APIs hold. That’s a logout, not a cache refresh, so don’t call it unless you mean it. The localStorage guide explains why data vanishing there is usually a bug.
A full reset for a logout button
A full reset combines the calls above, and it suits a “log out” or “reset app” button. It’s too heavy for fixing a stale page.
fun resetWebView(webView: WebView) {
webView.clearCache(true)
webView.clearHistory()
CookieManager.getInstance().removeAllCookies(null)
CookieManager.getInstance().flush()
WebStorage.getInstance().deleteAllData()
webView.loadUrl("https://example.com/")
}
flush() writes the cookie state to persistent storage, so the removal survives an app kill. One trap: clearHistory() acts on the current list, so calling it before a new page loads can leave the old page as a back entry. If the back button misbehaves after a reset, the back button guide covers the usual handling.
Skip clearFormData() here. The reference says it only hides the autocomplete popup and doesn’t remove saved form data.
Clearing the cache from Android settings
A user can clear a WebView app’s cache without any code from the phone’s settings. The usual path is Settings > Apps > your app > Storage > Clear cache, though menu names vary by manufacturer, as this step-by-step guide shows.
Clear storage is the bigger hammer. It deletes the app’s data too, including saved logins. Tell support users to try Clear cache first.
This is the only option for apps you can’t change. If you built your app with webtoapkfree.com, a live website section loads your current site, and content changes reach users without an app update. Only bundled HTML, the icon and navigation need a new build.
Cache modes: when LOAD_NO_CACHE makes sense
setCacheMode changes how a WebView uses its cache from then on, rather than clearing it once. The WebSettings reference lists four modes, with LOAD_DEFAULT as the default:
- LOAD_DEFAULT: use cached copies while they haven’t expired, otherwise the network.
- LOAD_CACHE_ELSE_NETWORK: prefer the cache, even for expired copies.
- LOAD_NO_CACHE: skip the cache and always load from the network.
- LOAD_CACHE_ONLY: never touch the network.
The same reference explains a common surprise. On a normal load, content is revalidated as needed. When the user goes back, content isn’t revalidated and comes straight from the cache, so the back button can show an older page.
Some old answers also tell you to call setAppCacheEnabled(false). That method no longer appears on the WebSettings reference, so drop it from your code.
Fix stale content on the server instead
The cleaner fix for stale content is to send the right HTTP caching headers from your website, so the WebView knows when to check for updates. A WebView follows the same Cache-Control rules as a browser.
From the Cache-Control reference:
no-cachelets the response be stored but forces a check with the server before each reuse. Despite the name, it doesn’t mean “don’t cache”.no-storetells caches not to store the response at all.max-age=Nkeeps the response fresh for N seconds.immutablesays the response won’t change while fresh.
The setup I’d use: no-cache on HTML pages, and long max-age plus immutable on CSS and JS files whose names change with each release. The app then checks the HTML every time but reuses assets until you ship new ones.
For a one-off reset after a bad deploy, the Clear-Site-Data header asks the client to remove data for the site. The "cache" directive drops cached data, and "storage" also removes localStorage, IndexedDB and service worker registrations. Check browser support before relying on it. If your site uses a service worker, its own cache can serve old files too, which the service worker offline guide covers.
My take and one limitation
Don’t call clearCache(true) on every launch. It throws away cached assets, so each start is slower and the app shows nothing offline. Fix the headers once, and keep clearCache for a manual “refresh” button.
The limitation: none of this reaches users until they open the app, and server headers only apply to responses fetched after you change them. Copies already cached under an old max-age can stay until they expire, unless the user clears the cache. If pages still go blank after clearing, the white screen guide lists other causes, and you can watch cache hits live with Chrome DevTools.
FAQ
Does clearCache clear cookies in a WebView?
No. clearCache only clears the resource cache. Remove cookies with CookieManager.getInstance().removeAllCookies(null), which runs asynchronously.
Does clearCache affect every WebView in my app?
Yes. Android’s reference says the cache is per-application, so clearCache clears it for all WebViews the app uses, not only the one you call it on.
What is the difference between clearCache(true) and clearCache(false)?
With false, only the RAM cache is cleared. With true, the files cached on disk are cleared as well, which is what you want for stale content.
Can a user clear a WebView app’s cache without code?
Yes. In Android Settings, open Apps, pick the app, go to Storage and tap Clear cache. Clear storage goes further and also deletes saved logins and other app data.
Should I set LOAD_NO_CACHE to stop stale pages?
Usually not. LOAD_NO_CACHE skips the cache on every load, which makes the app slower and useless offline. Fix the Cache-Control headers on your site instead.