단일 버튼 클릭으로 캐시를 지울 수있는 테스트 응용 프로그램에서 fedor의 lazy loading list 구현을 사용하고 있습니다. 로드 된 이미지의 캐시 크기를 listview에서 가져 와서 프로그래밍 방식으로 캐시를 지우려면 어떻게해야합니까? 여기 안드로이드에서 캐시 크기를 얻는 방법
캐시 된 이미지를 저장하기위한 코드입니다public ImageLoader(Context context){
//Make the background thead low priority. This way it will not affect the UI performance.
photoLoaderThread.setPriority(Thread.NORM_PRIORITY-1);
mAssetManager = context.getAssets();
//Find the dir to save cached images
if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED))
cacheDir = new File(android.os.Environment.getExternalStorageDirectory(),"LazyList");
else
cacheDir = context.getCacheDir();
if(!cacheDir.exists())
cacheDir.mkdirs();
}
편집 : 나는 위해 clearCache() 메소드에이 코드 조각을 추가,하지만 난 여전히 볼 수 없습니다 그래서 기본적으로
스크롤 할 때 이미지가 다시로드되기 시작합니다.
public void clearCache() {
//clear memory cache
long size=0;
cache.clear();
//clear SD cache
File[] files = cacheDir.listFiles();
for (File f:files) {
size = size+f.length();
if(size >= 200)
f.delete();
}
}
난 그냥 이미지가 아래로 스크롤 한 후로드 볼 수 없습니다 아직도 내가 지금 사용하고 코드 내 질문을 편집 할 수 있지만. –
어디에서 캐시를 비우고 있습니까? 왜이 코드를 사용하는지 (size> = 200) f.delete(); –
다음과 같은 주요 활동에서 이것을 호출합니다. adapter.imageLoader.clearCache(); adapter.notifyDataSetChanged(); . 그리고 IF를 넣습니다. 왜냐하면 크기가 아마도 200kb에 도달 할 때 캐시를 삭제하기를 원하기 때문입니다. 그게 내가하고있는 일인가요? –