private Drawable getDrawable(Context con, String mall_type){
Drawable d = null;
if(mall_type.equals("B")){
d = con.getResources().getDrawable(R.drawable.bg_main_b);
}else if(mall_type.equals("C")){
d = con.getResources().getDrawable(R.drawable.bg_main_c);
}else if(mall_type.equals("D")){
d = con.getResources().getDrawable(R.drawable.bg_main_d);
}else if(mall_type.equals("E")){
d = con.getResources().getDrawable(R.drawable.bg_main_e);
}else{
d = con.getResources().getDrawable(R.drawable.bg_main_b);
}
return d;
}
public void showBackGroud(Context con,ImageView img){
try{
SharedPreferences pref = con.getSharedPreferences("account", Context.MODE_PRIVATE);
String mall_type = pref.getString("mall_type", "");
Drawable d = getDrawable(con,mall_type);
img.setBackgroundDrawable(d);
}catch(Exception e){
e.printStackTrace();
}
}
public void recycleBitmap(ImageView iv) {
Drawable d = iv.getBackground();
if(d==null){
return;
}
if (d instanceof BitmapDrawable) {
Bitmap b = ((BitmapDrawable)d).getBitmap();
if(!b.isRecycled()){
DevLog.e("msg","f:"+r.freeMemory());
DevLog.e("imageUtil", "recycled");
DevLog.e("msg","f:"+r.freeMemory());
b.recycle();
}
}
d.setCallback(null);
}
현재 다음과 같이 이미지를 불러오고, 리사이클링 하는 방식으로 만들었습니다.
리사이클링 시점은 onPause()시점입니다.
근데 리사이클링 되고
08-08 19:36:02.799: E/AndroidRuntime(9942): FATAL EXCEPTION: main
08-08 19:36:02.799: E/AndroidRuntime(9942): java.lang.RuntimeException: Canvas: trying to use a recycled bitmap android.graphics.Bitmap@41d0ae10
08-08 19:36:02.799: E/AndroidRuntime(9942): at android.graphics.Canvas.throwIfRecycled(Canvas.java:1047)
08-08 19:36:02.799: E/AndroidRuntime(9942): at android.graphics.Canvas.drawBitmap(Canvas.java:1151)
이 오류를 뱉어내내요..
onPause()시 자동으로 리소스를 리사이클링 하는 건가요??
그런데 리사이클링을 하지 않았을 시엔 Out Of Memory가 발생합니다.
이럴 경우 어떻게 처리를 하시나요?