I'm creating a news reader app that, at times, loads web pages into a WebView.

I noticed that with default behavior, the cache can get very unreasonable very quickly. Whether or not Android will clear out that cache when memory gets low, I'm not okay with my users seeing a 15MB news app when everything except the web cache is about 1MB.

However, I would love to use the cache to some extent. I saw WebSettings#setAppCacheMaxSize() and it seemed like it was just the ticket.

It doesn't seem like it does anything. I hardcoded the following into a method that is called by my activity's onCreate(), before anything is loaded:

originalSourceWebView.getSettings().setAppCacheMaxSize(300*1024); (I was using a larger, configurable value but dropped it lower to confirm my problem).

I blow right by 300KB without any fanfare, as shown by settings->applications->manage applications->click on my app. I'm listening in WebChromeClient#onReachedAppMaxCacheSize for events, but that never seems to trigger.

Has anyone successfully used this? Is there some different cache I should be trying to manage? The docs seem pretty sparse. I went into the android source but it just sends values off to native code, and I don't know how to delve into that.

My test environment is a nexus one on 2.2.2. I know that I'll need to make the cache calls by reflection in order to support 1.5 and 1.6, but if I can't make this work, there will be no need.

Edit
Report