title: Refresh the fragment after Camera Intent
body: <p>I am calling the Camera Intent from one of the fragments to save the image into gallery. The photo is taken and the image also gets saved in the gallery. I also have an adapter which gets all the images stored in the gallery into my application using GridView. So after taking the photo from the Camera Intent, I have to go back to another fragment and come back to see my photo refreshed in the GridView. So basically, I want to refresh the fragment once I am back from the Camera Intent. </p>
  
  <p>Here is the structure. I have a fragment called GalleryHomeFragment, from which I click a button and go to GalleryFragment. From there, I call the Camera Intent. My requirement is to refresh the GalleryFragment, once I come back from taking the picture, to see the pictures in my folders.</p>
  
  <p>Here is what I have tried so far. Posting the necessary code.</p>
  
  <p><strong>GalleryFragment.java</strong></p>
  
  <pre><code>cameraButton = (FloatingActionButton) view.findViewById(R.id.cameraBtn);
  
      cameraButton.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              dispatchTakePictureIntent();
          }
      });
  
      //gridView = (GridView) view.findViewById(R.id.gridView);
  
      gv_folder = (GridView)view.findViewById(R.id.gv_folder);
      gv_folder.setOnItemClickListener(new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView&lt;?&gt; adapterView, View view, int i, long l) {
              Intent intent = new Intent(getContext(), PhotosActivity.class);
              intent.putExtra("value",i);
              startActivity(intent);
          }
      });
  
      if ((ContextCompat.checkSelfPermission(getContext(),
              Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) &amp;&amp; (ContextCompat.checkSelfPermission(getContext(),
              Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED)) {
          if ((ActivityCompat.shouldShowRequestPermissionRationale(getActivity(),
                  Manifest.permission.WRITE_EXTERNAL_STORAGE)) &amp;&amp; (ActivityCompat.shouldShowRequestPermissionRationale(getActivity(),
                  Manifest.permission.READ_EXTERNAL_STORAGE))) {
  
          } else {
              ActivityCompat.requestPermissions(getActivity(),
                      new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE},
                      REQUEST_PERMISSIONS);
          }
      }else {
          Log.e("Else","Else");
          fn_imagespath();
      }
      setHasOptionsMenu(true);
  
      return view;
  }
  
  private void dispatchTakePictureIntent() {
      Intent takePictureIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
  
      // Ensure that there's a camera activity to handle the intent
      if (takePictureIntent.resolveActivity(getActivity().getPackageManager()) != null) {
          // Create the File where the photo should go
          File photoFile = null;
          try {photoFile = createImageFile();
  
          } catch (IOException ex) {
  
              Context context = getContext();
              CharSequence text = "Photo cannot be stored.";
              int duration = Toast.LENGTH_SHORT;
  
              Toast toast = Toast.makeText(context, text, duration);
              toast.show();
  
          }
          // Continue only if the File was successfully created
          if (photoFile != null) {
              Context context = getContext();
              Uri photoURI = FileProvider.getUriForFile(context,
                      "com.example.projectga.fileprovider",
                      photoFile);
              takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
              startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO);
  
          }else{
              Context context = getContext();
              CharSequence text = "Attention! Required to take picture!!";
              int duration = Toast.LENGTH_SHORT;
  
              Toast toast = Toast.makeText(context, text, duration);
              toast.show();
          }
      }
  }
  
  public void createFolder(){
      if (!directory.exists()){
          directory.mkdirs();
      }
  
  }
  
  private File createImageFile() throws IOException {
      createFolder();
      // Create an image file name
      Context context = getContext();
      String timeStamp = new SimpleDateFormat("dd-MMM-yyyy").format(new Date());
      String imageFileName = projectName + "_" + timeStamp + "_";
      File storageDir = getActivity().getExternalFilesDir(Environment.DIRECTORY_PICTURES);
      File image = File.createTempFile(
              imageFileName,  /* prefix */
              ".jpg",         /* suffix */
              storageDir      /* directory */
      );
  
      addImageToGallery(image, context);
  
      // Save a file: path for use with ACTION_VIEW intents
      mCurrentPhotoPath = "file:" + image.getPath();
      return image;
  }
  
  public static void addImageToGallery(File image, final Context context) {
      ContentValues values = new ContentValues();
  
      values.put(MediaStore.Images.Media.DATE_TAKEN, System.currentTimeMillis());
      values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg");
      values.put(MediaStore.MediaColumns.DATA, image.toString());
  
      context.getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
  
  }
  
   @Override
  public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
      search = menu.add("search").setIcon(R.drawable.ic_search_green_24dp).setShowAsActionFlags(1);
  
      super.onCreateOptionsMenu(menu, inflater);
  }
  
  public ArrayList&lt;Model_images&gt; fn_imagespath() {
      al_images.clear();
  
      int int_position = 0;
      Uri uri;
      Cursor cursor;
      int column_index_data, column_index_folder_name;
  
      String absolutePathOfImage = null;
      uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
  
      String[] projection = {MediaStore.MediaColumns.DATA, MediaStore.Images.Media.BUCKET_DISPLAY_NAME};
  
      final String orderBy = MediaStore.Images.Media.DATE_TAKEN;
      cursor = getContext().getContentResolver().query(uri, projection, null, null, orderBy + " DESC");
  
      column_index_data = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DATA);
      column_index_folder_name = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.BUCKET_DISPLAY_NAME);
      while (cursor.moveToNext()) {
          absolutePathOfImage = cursor.getString(column_index_data);
          Log.e("Column", absolutePathOfImage);
          Log.e("Folder", cursor.getString(column_index_folder_name));
  
          for (int i = 0; i &lt; al_images.size(); i++) {
              if (al_images.get(i).getStr_folder().equals(cursor.getString(column_index_folder_name))) {
                  boolean_folder = true;
                  int_position = i;
                  break;
              } else {
                  boolean_folder = false;
              }
          }
  
          if (boolean_folder) {
  
              ArrayList&lt;String&gt; al_path = new ArrayList&lt;&gt;();
              al_path.addAll(al_images.get(int_position).getAl_imagepath());
              al_path.add(absolutePathOfImage);
              al_images.get(int_position).setAl_imagepath(al_path);
  
          } else {
              ArrayList&lt;String&gt; al_path = new ArrayList&lt;&gt;();
              al_path.add(absolutePathOfImage);
              Model_images obj_model = new Model_images();
              obj_model.setStr_folder(cursor.getString(column_index_folder_name));
              obj_model.setAl_imagepath(al_path);
              al_images.add(obj_model);
          }
      }
  
      for (int i = 0; i &lt; al_images.size(); i++) {
          Log.e("FOLDER", al_images.get(i).getStr_folder());
          for (int j = 0; j &lt; al_images.get(i).getAl_imagepath().size(); j++) {
              Log.e("FILE", al_images.get(i).getAl_imagepath().get(j));
          }
      }
      obj_adapter = new Adapter_PhotosFolder(getContext(),al_images);
      gv_folder.setAdapter(obj_adapter);
      return al_images;
  }
  
  @Override
  public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
      super.onRequestPermissionsResult(requestCode, permissions, grantResults);
  
      switch (requestCode) {
          case REQUEST_PERMISSIONS: {
              for (int i = 0; i &lt; grantResults.length; i++) {
                  if (grantResults.length &gt; 0 &amp;&amp; grantResults[i] == PackageManager.PERMISSION_GRANTED) {
                      fn_imagespath();
                  } else {
                      Toast.makeText(getContext(), "The app was not allowed to read or write to your storage. Hence, it cannot function properly. Please consider granting it this permission", Toast.LENGTH_LONG).show();
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p><strong>GridViewAdapter.java</strong></p>
  
  <pre><code>Context context;
  ViewHolder viewHolder;
  ArrayList&lt;Model_images&gt; al_menu = new ArrayList&lt;&gt;();
  int int_position;
  
  
  public GridViewAdapter(Context context, ArrayList&lt;Model_images&gt; al_menu,int int_position) {
      super(context, R.layout.adapter_photosfolder, al_menu);
      this.al_menu = al_menu;
      this.context = context;
      this.int_position = int_position;
  
  
  }
  
  @Override
  public int getCount() {
  
      Log.e("ADAPTER LIST SIZE", al_menu.get(int_position).getAl_imagepath().size() + "");
      return al_menu.get(int_position).getAl_imagepath().size();
  }
  
  @Override
  public int getItemViewType(int position) {
      return position;
  }
  
  @Override
  public int getViewTypeCount() {
      if (al_menu.get(int_position).getAl_imagepath().size() &gt; 0) {
          return al_menu.get(int_position).getAl_imagepath().size();
      } else {
          return 1;
      }
  }
  
  @Override
  public long getItemId(int position) {
      return position;
  }
  
  
  @Override
  public View getView(final int position, View convertView, ViewGroup parent) {
  
      if (convertView == null) {
  
          viewHolder = new ViewHolder();
          convertView = LayoutInflater.from(getContext()).inflate(R.layout.adapter_photosfolder, parent, false);
          viewHolder.tv_foldern = (TextView) convertView.findViewById(R.id.tv_folder);
          viewHolder.tv_foldersize = (TextView) convertView.findViewById(R.id.tv_folder2);
          viewHolder.iv_image = (ImageView) convertView.findViewById(R.id.iv_image);
  
  
          convertView.setTag(viewHolder);
      } else {
          viewHolder = (ViewHolder) convertView.getTag();
      }
  
      viewHolder.tv_foldern.setVisibility(View.GONE);
      viewHolder.tv_foldersize.setVisibility(View.GONE);
  
  
  
      Glide.with(context).load("file://" + al_menu.get(int_position).getAl_imagepath().get(position))
              .diskCacheStrategy(DiskCacheStrategy.NONE)
              .skipMemoryCache(true)
              .into(viewHolder.iv_image);
  
  
      return convertView;
  
  }
  
  private static class ViewHolder {
      TextView tv_foldern, tv_foldersize;
      ImageView iv_image;
  }
  }
  </code></pre>
  
  <p><strong>Adapter_PhotosFolder.java</strong></p>
  
  <pre><code> Context context;
  ViewHolder viewHolder;
  ArrayList&lt;Model_images&gt; al_menu = new ArrayList&lt;&gt;();
  int int_position;
  
  
  public GridViewAdapter(Context context, ArrayList&lt;Model_images&gt; al_menu,int int_position) {
      super(context, R.layout.adapter_photosfolder, al_menu);
      this.al_menu = al_menu;
      this.context = context;
      this.int_position = int_position;
  
  
  }
  
  @Override
  public int getCount() {
  
      Log.e("ADAPTER LIST SIZE", al_menu.get(int_position).getAl_imagepath().size() + "");
      return al_menu.get(int_position).getAl_imagepath().size();
  }
  
  @Override
  public int getItemViewType(int position) {
      return position;
  }
  
  @Override
  public int getViewTypeCount() {
      if (al_menu.get(int_position).getAl_imagepath().size() &gt; 0) {
          return al_menu.get(int_position).getAl_imagepath().size();
      } else {
          return 1;
      }
  }
  
  @Override
  public long getItemId(int position) {
      return position;
  }
  
  
  @Override
  public View getView(final int position, View convertView, ViewGroup parent) {
  
      if (convertView == null) {
  
          viewHolder = new ViewHolder();
          convertView = LayoutInflater.from(getContext()).inflate(R.layout.adapter_photosfolder, parent, false);
          viewHolder.tv_foldern = (TextView) convertView.findViewById(R.id.tv_folder);
          viewHolder.tv_foldersize = (TextView) convertView.findViewById(R.id.tv_folder2);
          viewHolder.iv_image = (ImageView) convertView.findViewById(R.id.iv_image);
  
  
          convertView.setTag(viewHolder);
      } else {
          viewHolder = (ViewHolder) convertView.getTag();
      }
  
      viewHolder.tv_foldern.setVisibility(View.GONE);
      viewHolder.tv_foldersize.setVisibility(View.GONE);
  
  
  
      Glide.with(context).load("file://" + al_menu.get(int_position).getAl_imagepath().get(position))
              .diskCacheStrategy(DiskCacheStrategy.NONE)
              .skipMemoryCache(true)
              .into(viewHolder.iv_image);
  
  
      return convertView;
  
  }
  
  private static class ViewHolder {
      TextView tv_foldern, tv_foldersize;
      ImageView iv_image;
  }
  </code></pre>
  
  <p>Any help is appreciated. Thanks a lot in advance.</p>