title: How to Pass Drawable using Parcelable
body: <p>I have a class where i have an <code>Drawable</code> as an member.<br>
  This class i am using for sending data across activities as an <code>Parcelable</code> extra.   </p>
  
  <p>For that i have extended the parceble, and implemented the required functions.  </p>
  
  <p>I am able to send the basic data types using read/write int/string.<br>
  But i am facing problem while marshaling the Drawable object.  </p>
  
  <p>For that i tried to convert the <code>Drawable</code> to <code>byte array</code>, but i am getting class cast Exceptions. </p>
  
  <p>I am using following code to covert my Drawable to Byte array:</p>
  
  <pre><code>Bitmap bitmap = (Bitmap)((BitmapDrawable) mMyDrawable).getBitmap();
  ByteArrayOutputStream stream = new ByteArrayOutputStream();
  bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
  byte[]byteArray = stream.toByteArray();
  out.writeInt(byteArray.length);
  out.writeByteArray(byteArray);
  </code></pre>
  
  <p>And to convert byte array to Drawable i am using following code:</p>
  
  <pre><code>final int contentBytesLen = in.readInt();
  byte[] contentBytes = new byte[contentBytesLen];
  in.readByteArray(contentBytes);
  mMyDrawable = new BitmapDrawable(BitmapFactory.decodeByteArray(contentBytes, 0, contentBytes.length));
  </code></pre>
  
  <p>When i run this i get Class cast exception.</p>
  
  <p>How can we write/pass Drawable using the HashMap?<br>
  Is there any way by which we can pass Drawable in Parcel.  </p>
  
  <p>Thanks.</p>