title: Android onactivityresult() not being called in fragment
body: <p>This is my code for calling onactivity result. I am using a dialog which prompts to pick image from gallery or from camera. The same code is working in activity but is not working in fragments. I have tried all the previous answers on stackoverflow. Please help</p>
  
  <pre><code>AlertDialog.Builder builder = new AlertDialog.Builder(
                          getActivity());
  
                  builder.setTitle("Choose Image Source");
                  builder.setItems(new CharSequence[] { "Pick from Gallery",
                          "Take from Camera" },
                          new DialogInterface.OnClickListener() {
  
                              @Override
                              public void onClick(DialogInterface dialog,
                                      int which) {
                                  switch (which) {
                                  case 0:
  
                                      Intent intent = new Intent(
                                              Intent.ACTION_PICK,
                                              android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI);
  
                                      intent.putExtra("crop", "true");
                                      intent.putExtra("aspectX", 1);
                                      intent.putExtra("aspectY", 1);
                                      intent.putExtra("outputX", 250);
                                      intent.putExtra("outputY", 250);
  
                                      try {
  
                                          intent.putExtra("return-data", true);
                                          startActivityForResult(
                                                  Intent.createChooser(
                                                          intent,
                                                          "Complete action using"),
                                                  PICK_FROM_GALLERY);
  
                                      } catch (ActivityNotFoundException e) {
  
                                      }
  
                                      break;
  
                                  case 1:
  
                                      Intent takePictureIntent = new Intent(
                                              MediaStore.ACTION_IMAGE_CAPTURE);
                                      if (takePictureIntent
                                              .resolveActivity(getActivity()
                                                      .getPackageManager()) != null) {
  
                                          startActivityForResult(
                                                  takePictureIntent,
                                                  PICK_FROM_CAMERA);
  
                                      }
  
                                      break;
  
                                  default:
                                      break;
                                  }
                              }
                          });
                  builder.show();
  
  
  
  
  
  public void onActivityResult(int requestCode, int resultCode, Intent data) {
      // TODO Auto-generated method stub
  
      try {
          if (requestCode == PICK_FROM_GALLERY) {
              System.out.print("ho ja please");
              Bundle extras2 = data.getExtras();
              if (extras2 != null) {
                  bitmap = extras2.getParcelable("data");
  
                  Bitmap output = Bitmap.createBitmap(bitmap.getWidth(),
                          bitmap.getHeight(), Config.ARGB_8888);
  
  
                  dp.setImageBitmap(output);
  
  
              }
          }
  
          if (requestCode == PICK_FROM_CAMERA) {
  
              Bundle extras = data.getExtras();
              Bitmap bitmap1 = (Bitmap) extras.get("data");
  
              bitmap = Bitmap.createScaledBitmap(bitmap1, 250, 250, true);
  
              Bitmap output = Bitmap.createBitmap(bitmap.getWidth(),
                      bitmap.getHeight(), Config.ARGB_8888);
  
              dp.setImageBitmap(output);
  
  
  
          }
  </code></pre>