title: Android error: java.lang.OutOfMemoryError: bitmap size exceeds VM budget
body: <p>I came across many questions in stackoverflow regarding this error but non of them found explaining a proper solution for my scenario.</p>
  
  <p>In my android application I have to allow the user to click a button to open the Gallery and to select an image. And then needs to load that specific selected image to an ImageView in my layout(UI).</p>
  
  <p>Doing this is quite fine. Following is the code I am using to achieve this.</p>
  
  <p>In Upload button click -></p>
  
  <pre><code>        Intent intent = new Intent();
          intent.setType("image/*");
          intent.setAction(Intent.ACTION_GET_CONTENT);
          startActivityForResult(Intent.createChooser(intent,"Select Picture"), REQUEST_UPLOAD_IMG);
  </code></pre>
  
  <p>And then onActivityResult -></p>
  
  <pre><code>@Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) 
  {       
      //super.onActivityResult(requestCode, resultCode, data);        
      if(resultCode == Activity.RESULT_OK)
      {
          if(requestCode==REQUEST_UPLOAD_IMG)
          {               
              Uri selectedImageURI = data.getData();
              uploadImgVW.setImageURI(selectedImageURI);              
          }
          else
          {
              Toast.makeText(MainActivity.this, "You can only select an Image.", Toast.LENGTH_LONG).show();
          }
      }
  }
  </code></pre>
  
  <p>But if user select an image with a higher size (Like <strong>2MB</strong> of size), the application quit with the following Error. But It's quite fine with normal(KB level) images and wonder what I can do for this issue(To handle this error situation). Thanks...</p>
  
  <p>Error -></p>
  
  <pre><code>06-20 16:43:58.445: E/AndroidRuntime(2075): FATAL EXCEPTION: main
  06-20 16:43:58.445: E/AndroidRuntime(2075): java.lang.OutOfMemoryError: bitmap size exceeds VM budget
  </code></pre>