안녕하세요 안드로이드 초보 개발자입니다.
LruCache 사용중인데요 일단 소스부터 보시죠..
package com.newtalktalk.utils;
import java.io.InputStream;
import java.net.URL;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.support.v4.util.LruCache;
import android.util.Log;
import android.widget.ImageView;
public class DownLoadimage extends AsyncTask<String, Void, Bitmap> {
private ImageView imgview;
private int size = 1024*1024*4;
private static LruCache<String, Bitmap> lucha ;
public DownLoadimage(ImageView img) {
// TODO Auto-generated constructor stub
imgview = img;
if(lucha == null){
lucha = new LruCache<String, Bitmap>(size);
}
}
@Override
protected Bitmap doInBackground(String... urls) {
// TODO Auto-generated method stub
String dataurl = urls[0];
Bitmap imgbitmap = null;
try{
if(lucha.get(dataurl) == null){
Log.d("--", "NULL ");
InputStream in = new URL(dataurl).openStream();
BitmapFactory.Options option = new BitmapFactory.Options();
option.inSampleSize = 4;
imgbitmap = BitmapFactory.decodeStream(in,null,option);
lucha.put(dataurl, imgbitmap);
}else{
Log.d("--", "not NULL ");
imgbitmap = lucha.get(dataurl);
}
}catch (Exception e) {
// TODO: handle exception
Log.d("ErrorLog", "DownLoadimage : = " + e.toString());
}
return imgbitmap;
}
@Override
protected void onPostExecute(Bitmap result) {
// TODO Auto-generated method stub
if(result != null){
if(imgview != null){
imgview.setImageBitmap(result);
}
}
}
}
이렇게 구현햇는데요.. 제가 원하는데로 이미지를 저장햇다가 저장되어 있는 bitmap이 있으면 다시 로딩 하지 않는데요.
삭제 시점을..어떤식으로 구현해야 할지 모르겟습니다..
앱을 종료하고 다시 시작하면 static으로 구현해놔서 계속 가지구 있더군요..
이걸 없애줘야 할것 같은데.. 고수님들의 조언 기다리겠습니다..