1
는 여기내가 만든 캐시에 무언가가 있는지 테스트하는 방법은 무엇입니까?
public void putBitmapInDiskCache(URI imageUri, Bitmap avatar) {
File cacheDir = new File(this.getCacheDir(), "thumbnails");
cacheDir.mkdirs();
File cacheFile = new File(cacheDir, ""+imageUri.hashCode());
try {
cacheFile.createNewFile();
FileOutputStream fos = new FileOutputStream(cacheFile);
avatar.compress(CompressFormat.PNG, 100, fos);
fos.flush();
fos.close();
} catch (Exception e) {
Log.e("error", "Error when saving image to cache. ", e);
}
}
내가 뭔가 내 비동기 작업의 캐시의 내부에있는 경우 테스트 할 것 아니 내 이미지에 대한 캐시를 만들었습니다.
여기 내 무언가 거기에 뭔가가 있는지 테스트하고 싶습니다. 살해 신청 전에로드 된 이미지들.
//the important AsyncTask method. running the background thread to get the images and set them to the gallery.
private class MyTask extends AsyncTask<Void, Void, Void>{
@Override
protected Void doInBackground(Void... arg0) {try {
getImages();
Log.v("MyTask", "Image 1 retreived");
getImage2();
Log.v("MyTask", "Image 2 retreived");
getImage3();
Log.v("MyTask", "Image 3 retreived");
getImage4();
Log.v("MyTask", "Image 4 retreived");
} catch (IOException e) {
Log.e("MainMenu retreive image", "Image Retreival failed");
e.printStackTrace();
}
return null;
}
위의 코드에서 어떻게 그럴 수 있습니까? –
파일이 존재하지 않으면 예외를 throw 할 수있는 getImage 함수에서 사용할 수 있습니다. 당신이 할 수있는 일은 이미지 이름/경로를 함수에 전달하여 getImage 함수를 generic으로 만드는 것이다. –