title: java.lang.IllegalStateException: Fragment not attached to Activity
body: <p>I am rarely getting this error while making an API call.</p>
  
  <pre><code>java.lang.IllegalStateException: Fragment  not attached to Activity
  </code></pre>
  
  <p>I tried putting the code inside <code>isAdded()</code> method to check whether  fragment is currently added to its activity but still i rarely gets this error. I fail to understand why I am still getting this error. How can i prevent it?</p>
  
  <p>Its showing error on the line-</p>
  
  <pre><code>cameraInfo.setId(getResources().getString(R.string.camera_id));
  </code></pre>
  
  <p>Below is the sample api call that i am making.     </p>
  
  <pre><code>SAPI.getInfo(getActivity(),
                  new APIResponseListener() {
                      @Override
                      public void onResponse(Object response) {
  
  
                          cameraInfo = new SInfo();
                          if(isAdded()) {
                              cameraInfo.setId(getResources().getString(R.string.camera_id));
                              cameraInfo.setName(getResources().getString(R.string.camera_name));
                              cameraInfo.setColor(getResources().getString(R.string.camera_color));
                              cameraInfo.setEnabled(true);
                          }
  
  
                      }
  
                      @Override
                      public void onError(VolleyError error) {
                          mProgressDialog.setVisibility(View.GONE);
                          if (error instanceof NoConnectionError) {
                              String errormsg = getResources().getString(R.string.no_internet_error_msg);
                              Toast.makeText(getActivity(), errormsg, Toast.LENGTH_LONG).show();
                          }
                      }
                  });
  </code></pre>