title: How to call a Progress Dialog in Fragment?
body: <p>I have a activity in which adds two Tabs namely frag1 and frag2. In frag1, I am sending server request and a progress dialog is shown to user, But getting error in Dismissing dialog. How can I acheive this problem.</p>
  
  <p>error code:-</p>
  
  <pre><code>java.lang.IllegalArgumentException: View=com.android.internal.policy.impl.PhoneWindow$DecorView{4274d0d8 V.E..... R......D 0,0-456,144} not attached to window manager
  </code></pre>
  
  <p>Frag1 Dialog code:-</p>
  
  <pre><code>private void postDealListingDatatoServer() {
      try {
          String json;
          // 3. build jsonObject
          final JSONObject jsonObject = new JSONObject();// making object of Jsons.
          jsonObject.put("agentCode", m_szMobileNumber);// put mobile number
          jsonObject.put("pin", m_szEncryptedPassword);// put password
  
  
          Log.e(TAG, "Intial Record Count::" + sz_RecordCount);
          Log.e(TAG, "Intial Last Count::" + sz_LastCount);
          // 4. convert JSONObject to JSON to String
          json = jsonObject.toString();// convert Json object to string
  
          Log.i(TAG, "Server Request:-" + json);
  
          m_Dialog = DialogUtils.showProgressDialog(getActivity(), "Loading...");
  
          final String m_DealListingURL = "http://202.131.144.132:8080//getDealListInJSON";
          JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, m_DealListingURL, jsonObject, new Response.Listener&lt;JSONObject&gt;() {
              @Override
              public void onResponse(JSONObject response) {
                  Log.i(TAG, "Server Response:-" + response);
                  if (m_Dialog != null &amp;&amp; m_Dialog.isShowing()) {
                      m_Dialog.dismiss();
                  }
                  try {
                      int nResultCodeFromServer = Integer.parseInt(response.getString("resultcode"));
                      if (nResultCodeFromServer == m_TRANSACTION_SUCCESSFUL) {
                          JSONArray posts = response.optJSONArray("dealList");// get Deal list in array from response
                          s_oDataset.clear();
                          for (int i = 0; i &lt; posts.length(); i++) {// loop for counting deals from server
                              JSONObject post = posts.getJSONObject(i);// counting deal based on index
                              item = new CDealAppDatastorage();// creating object of DealAppdata storage
                              item.setM_szHeaderText(post.getString("dealname"));// get deal name from response
                              item.setM_szsubHeaderText(post.getString("dealcode"));// get dealcode from response
                              item.setM_szDealValue(post.getString("dealvalue"));// get deal value from response
                              item.setM_n_Image(m_n_FormImage[i]);//set Image Index wise(Dummy)
                              s_oDataset.add(item);// add all items in ArrayList
  
                          }
                          if (!s_oDataset.isEmpty()) {// condition if data in arraylist is not empty
                              m_oAdapter = new CDealAppListingAdapter(getActivity(), s_oDataset);// create adapter object and add arraylist to adapter
                              m_ListView.setAdapter(m_oAdapter);//adding adapter to recyclerview
                              m_NoInternetWarning.setVisibility(View.GONE);
                              mSwipeRefresh.setVisibility(View.VISIBLE);
  
                          } else {
                              m_ListView.removeFooterView(mFooter);// else Load buttonvisibility set to Gone
                          }
                      }
                      if (nResultCodeFromServer == m_kCONNECTION_LOST) {//server based conditions
                          CSnackBar.getInstance().showSnackBarError(m_Main.findViewById(R.id.mainLayout), "Connection Lost !", getActivity());
                      } else if (nResultCodeFromServer == m_kDEAL_NOT_FOUND) {// serevr based conditions .....
                          CSnackBar.getInstance().showSnackBarError(m_Main.findViewById(R.id.mainLayout), "No more deals available", getActivity());
                      } else if (nResultCodeFromServer == m_kTECHNICAL_FAILURE) {
                          CSnackBar.getInstance().showSnackBarError(m_Main.findViewById(R.id.mainLayout), "Technical Failure", getActivity());
                      } else if (nResultCodeFromServer == m_kTIMED_OUT) {
                          CSnackBar.getInstance().showSnackBarError(m_Main.findViewById(R.id.mainLayout), "Timed Out", getActivity());
                      } else if (nResultCodeFromServer == m_kUNKNOWN_ERROR) {
                          CSnackBar.getInstance().showSnackBarError(m_Main.findViewById(R.id.mainLayout), "Unknown Error", getActivity());
                      } else if (nResultCodeFromServer == m_kALREADY_AVAIL_BENEFIT) {
                          CSnackBar.getInstance().showSnackBarError(m_Main.findViewById(R.id.mainLayout), "You have already avail the benefit of this deal", getActivity());
                      }
  
                  } catch (JSONException e) {
                      e.printStackTrace();
                  }
              }
          }, new Response.ErrorListener() {
              @Override
              public void onErrorResponse(VolleyError error) {
                  Log.e(TAG, "Server error:-" + error);
                  if (m_Dialog != null &amp;&amp; m_Dialog.isShowing()) {
                      m_Dialog.dismiss();
                  }
                  if (error instanceof TimeoutError) {
                      CSnackBar.getInstance().showSnackBarError(m_Main.findViewById(R.id.mainLayout), "Connection lost ! Please try again", getActivity());
                      mSwipeRefresh.setVisibility(View.GONE);
                      m_NoInternetWarning.setVisibility(View.VISIBLE);
                  } else if (error instanceof NetworkError) {
                      CSnackBar.getInstance().showSnackBarError(m_Main.findViewById(R.id.mainLayout), "No internet connection", getActivity());
                      mSwipeRefresh.setVisibility(View.GONE);
                      m_NoInternetWarning.setVisibility(View.VISIBLE);
                  }
              }
          });
          RequestQueue requestQueue = Volley.newRequestQueue(getActivity());
          requestQueue.add(jsonObjectRequest);
      } catch (JSONException e) {
          e.printStackTrace();
      }
  
  }
  </code></pre>
  
  <p>here I am getting error in dismissing dialog.</p>
  
  <p>DialogUtils class code:-</p>
  
  <pre><code>public class DialogUtils {
  
  public static ProgressDialog showProgressDialog(Context context, String message) {
      ProgressDialog m_Dialog = new ProgressDialog(context);
      m_Dialog.setMessage(message);
      m_Dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
      m_Dialog.setCancelable(false);
      m_Dialog.show();
      return m_Dialog;
  
  }
  
  }
  </code></pre>