title: Android Drawables: outofmemoryerror VERSUS "cannot draw recycled bitmaps" error
body: <p>I've read a ton of posts about both these errors and can't seem to find a solution that works for me. 
  I have a basic listview activity of animals. When you click on an item in the list, it opens the AnimalViewActivity and displays a simple png image inside an ImageView.</p>
  
  <p>Here's where I set the image for the ImageView:</p>
  
  <pre><code>public void getImage() {
  
      String imageName = myService.yourAnimals.get(key).getType();
      System.out.println(imageName);
  
      Resources res = getResources();
      int resourceId = res.getIdentifier(imageName, "drawable", getPackageName() );
      Drawable drawable = res.getDrawable( resourceId );
      image.setImageDrawable( drawable );
  }
  </code></pre>
  
  <p>Then when I leave AnimalViewActivity to return to the listview activity, I do this:</p>
  
  <pre><code>@Override
  protected void onDestroy() {
      super.onDestroy();
      //((BitmapDrawable)image.getDrawable()).getBitmap().recycle();
      image.getDrawable().setCallback(null);
      //System.gc();
      System.out.println("Destroy image!");
  }
  </code></pre>
  
  <p>If I uncomment the recycle() line, I get the  "cannot draw recycled bitmaps" error.
  If I leave it how it is, I get the  outofmemoryerror for bitmapfactory.</p>
  
  <p>java.lang.IllegalArgumentException: Cannot draw recycled bitmap
  OR
  java.lang.OutOfMemoryError
  android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)</p>
  
  <p>Either one of these errors occur after I've opened the ViewAnimalActivity about 20 times and the app crashes. 
  The only thing that seems to work forever is System.gc() , but I know that is not a good solution.</p>
  
  <p>I'm testing it in android4.1, but the minSDK is set to android3.0 </p>
  
  <p>I read that the javaVM error for bitmap recycling was fixed in 3.0?</p>
  
  <p>For some reason, garbage collection is not happening fast enough without explicitly calling the gc. These images are small, mostly between 100-300kB.</p>
  
  <p>Any ideas?</p>
  
  <p>EDIT:
  It seems happier with<br>
  image.setImageDrawable( null );</p>
  
  <p>I think I tried this before when I still had it set on Android2.2, but Android3.0 is happy with it so far.</p>