title: Fragment onActivityResult returns null
body: <p>In the app I'm developing, the user can define an image on his profile. The first time the app is executed, an intro activity is shown where the user can choose between selecting a photo from the galery or taking a new one with the camera.</p>
  
  <p>This works fine. After the user sets a profile pic, I save it in the app folder and I can use that pic inside the app later.</p>
  
  <p>My app is based on the Navigation Drawer (support) so it is composed by fragments. One of this fragments is for the user's profile where the profile pic is shown. here, the user has te chance to change this pic again. An here is where I'm getting troubles.</p>
  
  <p>To select a new pic, I'm using the same code I used to get the pic in the intro activity, just adapting some things to the fragment (putting getActivity()). But it seems that is not returning the image to the fragment and it's throwing a NPE.</p>
  
  <p>This is how the pic is selectect from gallery in SettingsFragment:</p>
  
  <pre><code>Intent galleryIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
  galleryIntent.setType("image/*");
  startActivityForResult(galleryIntent, PICK_IMAGE_REQUEST_FRAG);
  </code></pre>
  
  <p>And here is the onActivityResult in SettingsFragment too:</p>
  
  <pre><code>@Override
  public void onActivityResult(int requestCode, int resultCode, Intent data) {
      super.onActivityResult(requestCode, resultCode, data);
      switch (requestCode) {
          case PICK_IMAGE_REQUEST_FRAG:
              if (resultCode == getActivity().RESULT_OK &amp;&amp; data != null) {
                  /*We get the image URI*/
                  Uri selectedImageUri = data.getData();
                  Bitmap srcBmp = null;
                  try {
                      srcBmp = MediaStore.Images.Media.getBitmap(getActivity().getContentResolver(), selectedImageUri);
                  } catch (FileNotFoundException e) {
                      Log.e("GET_IMAGE", e.getMessage(), e);
                  } catch (IOException e) {
                      Log.e("GET_IMAGE", e.getMessage(), e);
                  }
  
                  /*Transform the original image to landscape to use it as profile background*/
                  Bitmap landBmp = null;
                  if (srcBmp.getWidth() &lt;= srcBmp.getHeight()) {
                      landBmp = Bitmap.createBitmap(
                              srcBmp,
                              0,
                              srcBmp.getHeight()/2 - srcBmp.getWidth()/2, //srcBmp.getHeight()/4 ?
                              srcBmp.getWidth(),
                              srcBmp.getWidth() /2
                      );
                  }
  
                  /*Scale the bitmap*/
                  int originalWidth = srcBmp.getWidth();
                  int originalHeight = srcBmp.getHeight();
                  int newWidth = 400;
                  int newHeight = (originalHeight*newWidth)/originalWidth;
                  Bitmap fullbitmap = Bitmap.createScaledBitmap(landBmp, newWidth, newHeight, true);
                  /*Save the bitmap in app-folder*/
                  ContextWrapper cw1 = new ContextWrapper(getActivity().getApplicationContext());
                  File directory1 = cw1.getDir("profile", Context.MODE_PRIVATE);
                  if (!directory1.exists()) {
                      directory1.mkdir();
                  }
                  File filepath1 = new File(directory1, "profile_pic.png");
                  FileOutputStream fos1 = null;
                  try {
                      fos1 = new FileOutputStream(filepath1);
                      fullbitmap.compress(Bitmap.CompressFormat.PNG, 100, fos1);
                      fos1.close();
                  } catch (Exception e) {
                      Log.e("SAVE_FULL_IMAGE", e.getMessage(), e);
                  }
  
                  /*Show background profile pic*/
                  Drawable drawable = new BitmapDrawable(getResources(), fullbitmap);
                  header_container.setBackgroundDrawable(drawable);
              }
              break;
  </code></pre>
  
  <p>But as said, the app crashes an this is what logcat tells:</p>
  
  <pre><code>java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=131073, result=-1, 
      data=Intent { dat=content://media/external/images/media/204 flg=0x1 }}   
      to activity {com.myproject.executer/com.myproject.executer.MainActivity}: 
  java.lang.NullPointerException at android.app.ActivityThread.deliverResults(ActivityThread.java:3389)
  
  Caused by: java.lang.NullPointerException at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:590) 
      at com.myproject.executer.SettingsFragment.onActivityResult(SettingsFragment.java:275)
  </code></pre>
  
  <p>Where line 275 is <code>Bitmap fullbitmap = Bitmap.createScaledBitmap(landBmp, newWidth, newHeight, true);</code></p>
  
  <p>So, I don't understand well what is happening, because it says something that is failing to deviler the result to MainActivity , and it has to deliver the result to SettingsFragment.</p>