title: Serializing a Drawable object on Android
body: <p>I'm trying to speed up my ListView by cacheing the images and loading them from the phone rather than the internet when scrolling the list. However, I run into an exception when I try to serialize the Drawable object. This is my function:</p>
  
  <pre><code>    private void cacheImage(Drawable dr, Article a){
      FileOutputStream fos;
      try {
          fos = openFileOutput(a.getArticleId().toString(), Context.MODE_PRIVATE);
          ObjectOutputStream oos = new ObjectOutputStream(fos);
          oos.writeObject(dr); 
          oos.close();
      } catch (FileNotFoundException e) {
          e.printStackTrace();
      }catch(IOException e){
          e.printStackTrace();
      }
  }
  </code></pre>
  
  <p>This nifty bit of code results in: </p>
  
  <p><strong>java.io.NotSerializableException: android.graphics.drawable.BitmapDrawable</strong></p>
  
  <p>What is the best approach to serialize these images?</p>