Hi there.
I'm working on an app, and although this may seem like a minor issue, I can't seem to get it fixed. Also, no reply over at my usual go-to Q&A site StackOverflow. I really need an answer, so any thoughts would be VERY much appreciated!
I am building a native app, where (at least) one part is a web app, disguised as a native app. Where Facebook showed us how important it is to use good caching, I'm caching the webpage, so it feels like a native part of the app when you load it for the second time. However, the way I've set it up, the cached content is permanent. So if I change something on the server, the old cached content still shows.
Here's what I'd like the achieve in the order of preferability, 1 being the most preferable.
EDIT > But I'm desperate and would go for 2 in a heartbeat!
Here's the code I'm currently using.
Any help would be VERY much appreciated!
I'm working on an app, and although this may seem like a minor issue, I can't seem to get it fixed. Also, no reply over at my usual go-to Q&A site StackOverflow. I really need an answer, so any thoughts would be VERY much appreciated!
I am building a native app, where (at least) one part is a web app, disguised as a native app. Where Facebook showed us how important it is to use good caching, I'm caching the webpage, so it feels like a native part of the app when you load it for the second time. However, the way I've set it up, the cached content is permanent. So if I change something on the server, the old cached content still shows.
Here's what I'd like the achieve in the order of preferability, 1 being the most preferable.
- EITHER The cached content shows first. In the background, the page checks for a newer version, but only reloads if the content is different.
- OR The cached content shows first. In the background the page refreshes and reloads.
- OR The cached content is erased after X time (a week?), forcing the page to reload.
EDIT > But I'm desperate and would go for 2 in a heartbeat!
Here's the code I'm currently using.
Code:
WebView wv = (WebView) v.findViewById(ref_id);
wv.getSettings().setJavaScriptEnabled(true);
wv.getSettings().setDatabaseEnabled(true);
String appDBPath = v.getContext().getApplicationContext().getDatabasePath("AppConstructor").getAbsolutePath();
wv.setWebChromeClient(new WebChromeClient() {
@Override
public void onReachedMaxAppCacheSize(long spaceNeeded,
long totalUsedQuota, WebStorage.QuotaUpdater quotaUpdater) {
quotaUpdater.updateQuota(spaceNeeded * 2);
}
@Override
public void onExceededDatabaseQuota(String url,
String databaseIdentifier, long currentQuota,
long estimatedSize, long totalUsedQuota,
WebStorage.QuotaUpdater quotaUpdater) {
quotaUpdater.updateQuota(estimatedSize * 2);
}
});
wv.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
wv.getSettings().setDomStorageEnabled(true);
wv.getSettings().setAppCacheMaxSize(1024 * 1024 * 8);
String appCachePath = v.getContext().getApplicationContext().getCacheDir().getAbsolutePath();
wv.getSettings().setAppCachePath(appCachePath);
wv.getSettings().setAllowFileAccess(true);
wv.getSettings().setAppCacheEnabled(true);
wv.loadUrl(ref_arg1);
Core x = new Core();
wv.addJavascriptInterface(x.new JavaScriptInterface(v.getContext()),"Android");
Any help would be VERY much appreciated!