开发者

How to recycle bitmap from android Gallery::GetView method

开发者 https://www.devze.com 2023-02-11 09:27 出处:网络
IngetView method of gallery , i had download the bitmap and set to Imageview and return it back to framework.

In getView method of gallery , i had download the bitmap and set to Imageview and return it back to framework. When and where should i recycle the bitmap ? I don't want to wake up the system garbage collector to clean up the bitmaps.

public View getView(int position, View view, ViewGroup parent) {
        ImageView i = new ImageView(mContext); 
        downloadFromWeb("www.blahblah.com", i);
        i.setScaleType(ImageView.ScaleType.FIT_XY);
        i.setLayoutParams(new Gallery.LayoutParams(mDisplayWidth, 开发者_运维百科(mDisplayHeight-100)));
        i.setBackgroundResource(mGalleryItemBackground);
        return i;
    }

public downloadFromWeb(URL url, ImageView i){
        Bitmap bitmap = getBitmapFromWeb(url);
        i.setImageBitmap(bitmap);
  }


    You can call bitmap recycle method in onDestory method as shown below

Bitmap mybitmap= null;

@Override
    protected void onDestroy() {
        super.onDestroy();

        if(bm!=null)
        mybitmap.recycle();

    }
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号