Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cant parcel a recycled bitmap error

Tags:

android

I am trying to add image to camera surfaceview and tried to get that image by using the following code.

       else if(v.equals(findViewById(R.id.ok_button))){
//                saveImage();

                topbar.setVisibility(View.GONE);
                menubar.setVisibility(View.GONE);
                bottom.setVisibility(View.GONE);

                View s = ml.getRootView();
                s.setDrawingCacheEnabled(true);

                Bitmap b = s.getDrawingCache();


                Bitmap watermarkimage=b;
                s.setVisibility(View.GONE);
                Log.e("ok","ok");
                Intent i=new Intent(CameraActivity.this,Update.class);
                 i.putExtra("data",watermarkimage);
                 startActivity(i);
                 finish();
                 }

I saved the whole activity to get the image.And by using the following code I got the Bitmap

 View s = ml.getRootView();
                s.setDrawingCacheEnabled(true);

                Bitmap b = s.getDrawingCache();

When I tried to send this bitmap to Another Activity I am getting this error

12-05 17:58:38.700: E/AndroidRuntime(10590): FATAL EXCEPTION: main
12-05 17:58:38.700: E/AndroidRuntime(10590): java.lang.IllegalStateException: Can't parcel a recycled bitmap
12-05 17:58:38.700: E/AndroidRuntime(10590):    at android.graphics.Bitmap.checkRecycled(Bitmap.java:210)
12-05 17:58:38.700: E/AndroidRuntime(10590):    at android.graphics.Bitmap.writeToParcel(Bitmap.java:960)
12-05 17:58:38.700: E/AndroidRuntime(10590):    at android.os.Parcel.writeParcelable(Parcel.java:1151)
12-05 17:58:38.700: E/AndroidRuntime(10590):    at android.os.Parcel.writeValue(Parcel.java:1070)
12-05 17:58:38.700: E/AndroidRuntime(10590):    at android.os.Parcel.writeMapInternal(Parcel.java:488)
12-05 17:58:38.700: E/AndroidRuntime(10590):    at android.os.Bundle.writeToParcel(Bundle.java:1552)
12-05 17:58:38.700: E/AndroidRuntime(10590):    at android.os.Parcel.writeBundle(Parcel.java:502)
12-05 17:58:38.700: E/AndroidRuntime(10590):    at android.content.Intent.writeToParcel(Intent.java:5492)
12-05 17:58:38.700: E/AndroidRuntime(10590):    at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:1341)
12-05 17:58:38.700: E/AndroidRuntime(10590):    at android.app.Instrumentation.execStartActivity(Instrumentation.java:1374)
12-05 17:58:38.700: E/AndroidRuntime(10590):    at android.app.Activity.startActivityForResult(Activity.java:2873)
like image 572
user1871951 Avatar asked Dec 05 '12 13:12

user1871951


1 Answers

Try making a copy or clone of this bitmap and parcel the copy.

Bitmap watermarkimage = b.copy(b.getConfig(), true);

I would hazard a guess that the data getDrawingCache returns is shared with b and watermarkimage. So perhaps setVisible to Gone is causing it to recycle.

like image 96
Emile Avatar answered Oct 29 '22 17:10

Emile