title: Assigning bitmap to ImageView via setImageURI throws OutOfMemory exception
body: <p>I have an activity with an empty ImageView and a button. After clicking the button, I display the device's media gallery, the user chooses an image that gets passed to the activity via an intent. I use the image's URI from the returned data and I populate the ImageView, like this:</p>
  
  <pre><code>private ImageView pic;
  
  @Override
  public void onCreate(Bundle savedInstanceState) 
  {
  
        pic = (ImageView)findViewById(R.id.bbChildImage);
  
  }
  
  protected void onActivityResult(int requestCode, int resultCode, Intent data) 
  {  
  
          if(resultCode == RESULT_OK)
          {   
              URI currImageURI = data.getData();
              pic.setImageURI(currImageURI);
          }
  }
  </code></pre>
  
  <p>Now, if I go to choose another image from the gallery, after the data is returned, I get a bitmap related OutOfMemory exception. </p>
  
  <p>I figured out two ways to get rid of it. I either do this before assigning the URI:</p>
  
  <pre><code>((BitmapDrawable)pic.getDrawable()).getBitmap().recycle();
  </code></pre>
  
  <p>or instead of assigning the URI to the view, I retrieve the bitmap first, and then assign it, like this:</p>
  
  <pre><code>Bitmap thumbnail = MediaStore.Images.Media.getBitmap(this.getContentResolver(), currImageURI);
  pic.setImageBitmap(thumbnail);
  </code></pre>
  
  <p>I am not sure which one is better. Also, if there are better ways, I would appreciate the feedback.</p>
  
  <p>Thanks.</p>