안드로이드 웹 캐시 삭제
출처 : http://www.androidpub.com/265895
웹뷰를 자주쓰다보면 안드로이드가 자동으로 캐싱을하여 같은 요청에 대해서는 웹뷰에 변화를 보려해도 앱을 삭제후 재설치 하지 않는 한 디버깅하기 힘듭니다. 그래서 안드로이드 내부적으로 쌓이는 캐시를 삭제해줘서 다음번 앱이 실행될때 새로운 요청을 받게하면 웹뷰의 변화를 볼 수 있습니다.
@Override
protected void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
clearApplicationCache(null);
}
/**
* 웹뷰에 케시가 쌓이는것을 앱이 종료할때마다 비우는 함수
*/
public void clearApplicationCache(java.io.File dir){
if(dir == null){
dir = getCacheDir();
}
if(dir == null){
return ;
}
java.io.File[] children = dir.listFiles();
try{
for(int i=0; i<children.length; i++){
if(children[i].isDirectory()){
clearApplicationCache(children[i]);
}else{
children[i].delete();
}
}
}catch(Exception e){
Toast.makeText(mContext , "캐시 삭제 실패", 10000).show();
}
}
함수를 호출만하면 되는데 보통 onDestroy 때 걸어주시면 적당합니다.