定时清理缓存
首先在Application里面创建定时器
private boolean isMoreThanTenMinutes = false;
private Handler tenMinutesHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
isMoreThanTenMinutes = true;
}
};
public boolean isMoreThanTenMinutes() {
return isMoreThanTenMinutes;
}
public void startTenMinutesHandler() {
tenMinutesHandler.sendEmptyMessageDelayed(0, tenMinutes);
isMoreThanTenMinutes = false;
}
在Application的onCreate方法中去开启定时器
@Override
public void onCreate() {
super.onCreate();
startTenMinutesHandler();
}
当WebView加载的时候去判断
boolean moreThanTenMinutes = Application.getInstance().isMoreThanTenMinutes();
if (moreThanTenMinutes) {
webview.clearCache(true);
Application.getInstance().startTenMinutesHandler();
}
settings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);