recycle View Background Resource - Android User Interface

Android examples for User Interface:View Background

Description

recycle View Background Resource

Demo Code


import android.graphics.Bitmap;
import android.graphics.drawable.AnimationDrawable;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

public class Main{
    private static final String TAG = "ForceGCUtils";
    //  w ww  .  j  a va2 s.c o  m
    public static void recycleViewBackgroundResource(View view) {
        if (view == null) {
            return;
        }
        Drawable drawable = view.getBackground();
        if (drawable instanceof BitmapDrawable) {
            Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
            if (bitmap != null && !bitmap.isRecycled()) {
                LogUtils.d(TAG, "imageview recycle background bitmap!");
                if (SDKVersionUtils.hasJellyBean()) {
                    view.setBackground(null);
                } else {
                    view.setBackgroundDrawable(null);
                }
                bitmap.recycle();
            }
        }
    }
}

Related Tutorials