Java.lang.RuntimeException:Canvas:trying to use a recycled bitmap android.graphics.bitmap@412d7230

Source: Internet
Author: User

Recently encountered an error such as title, record the workaround again. This article refers to the post:

http://bbs.csdn.net/topics/390196217

This bug occurs because of a memory recycle with the Bitamp code:

top= (ImageView) View.findviewbyid (r.id.top); Bitmap=imgbitmap.comefromres (Getresources (), r.drawable. top); Top.setimagebitmap (bitmap); bottom= (ImageView) View.findviewbyid (R.id.bottom); Bitmap1=imgbitmap.comefromres ( Getresources (), r.drawable. bottom); Bottom.setimagebitmap (BITMAP1);

This should be the case when recycling:




@Overridepublic void OnDestroy () {//TODO auto-generated method Stubtop.setimagebitmap (null); Bottom.setimagebitmap ( NULL); imgbitmap.myrecycle (bitmap); imgbitmap.myrecycle (BITMAP1); Super.ondestroy ();}

Or

@Overridepublic void OnDestroy () {//TODO auto-generated method Stubimgbitmap.myrecycle (Mbitmap); Imgbitmap.myrecycle ( MBITMAP1); Top=null;bottom=null;super.ondestroy ();}

In addition the code for the Myrecycle method is as follows:
public static void Myrecycle (Bitmap bmp) {if (!bmp.isrecycled () && null!=bmp) {bmp=null;}}}
In short, it has to beunbind all bindings related to bitmap.

Reprint Please specify source: http://blog.csdn.net/android_jiangjun/article/details/39698459




Java.lang.RuntimeException:Canvas:trying to use a recycled bitmap [email protected]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.