从别的地方找的资料,原文地址找不到了.....
import java.util.ArrayList;
import java.util.List;
import com.nostra13.universalimageloader.core.assist.FailReason;
import com.nostra13.universalimageloader.core.listener.ImageLoadingListener;
import android.graphics.Bitmap;
import android.view.View;
public class ReleaseBitmap implements ImageLoadingListener {
private List<Bitmap> mBitmaps;
public ReleaseBitmap() {
mBitmaps = new ArrayList<Bitmap>();
}
public void cleanBitmapList() {
if (mBitmaps.size() > 0) {
for (int i = 0; i < mBitmaps.size(); i++) {
Bitmap b = mBitmaps.get(i);
if (b != null && !b.isRecycled()) {
b.recycle();
}
}
}
}
@Override
public void onLoadingCancelled(String arg0, View arg1) {
}
@Override
public void onLoadingComplete(String arg0, View arg1, Bitmap arg2) {
}
@Override
public void onLoadingFailed(String arg0, View arg1, FailReason arg2) {
}
@Override
public void onLoadingStarted(String arg0, View arg1) {
}
}
在需要释放资源的地方:
ReleaseBitmap rb = new ReleaseBitmap();
rb.cleanBitmapList();`