title: How to call fragment from non activity class in android
body: <p>I have a Login <code>Fragment</code> and a Class named <em>CServerResponse</em>.</p>
  
  <p>I'd like to call <code>LoginFragment</code> from <code>CServerResponse</code> class.</p>
  
  <p>How can I do that?</p>
  
  <p>Here is the <code>CServerResponse</code> class code:</p>
  
  <pre><code>public class CServerResponse {
      public static CServerResponse s_m_oServerResponse;
      public Context m_Context;
  
      private CServerResponse(Context m_Context) {
          this.m_Context = m_Context;
      }
  
      public static CServerResponse getInstance() {
          if (s_m_oServerResponse == null) {
              s_m_oServerResponse = new CServerResponse();
          }
          return s_m_oServerResponse;
      }
  
      public void getLoginResponse() throws JSONException {
          final Fragment activity = (Fragment) m_Context;
          if (CLoginScreen.m_oResponseobject.getString("resultdescription").equalsIgnoreCase("Transaction Successful")) {
  
              CLoginScreen.m_oLoginSession.setLoginData(
                  CLoginScreen.s_szResponseMobile, CLoginScreen.s_szResponsePassword);
  
              getActivity().getSupportFragmentManager()
                           .beginTransaction()
                           .replace(R.id.container, new CDealMainListing()).commit();
  
              CToastMessage.getInstance().showToast(getActivity(), "You are successfully Logged In");
  
          } else if (m_oResponseobject.getString("resultdescription").equalsIgnoreCase("Agentcode Can Not Be Empty")) {
  
              CToastMessage.getInstance().showToast(getActivity(), "Please Enter Valid Mobile Number");
  
          } else if (m_oResponseobject.getString("resultdescription").equalsIgnoreCase("Pin Can Not Be Empty")) {
  
              CToastMessage.getInstance().showToast(getActivity(), "Please Enter Password");
  
          } else if (m_oResponseobject.getString("resultdescription").equalsIgnoreCase("Invalid PIN")) {
  
              CToastMessage.getInstance().showToast(getActivity(), "Please enter correct Password");
  
          } else if (m_oResponseobject.getString("resultdescription").equalsIgnoreCase("Subscriber/Agent Blocked due to Wrong Attempts")) {
  
              CToastMessage.getInstance().showToast(getActivity(), "You are blocked as You finished your all attempt");
  
          } else if (m_oResponseobject.getString("resultdescription").equalsIgnoreCase("Connection Not Available")) {
  
              CToastMessage.getInstance().showToast(getActivity(), "Connection Lost ! Please Try Again");
  
          } else if (m_oResponseobject.getString("resultdescription").equalsIgnoreCase("Subscriber/Agent Not Found")) {
  
              CToastMessage.getInstance().showToast(getActivity(), "User not found ! Kindly Regiter before Login");
  
          } else if (m_oResponseobject.getString("resultdescription").equalsIgnoreCase("OTP not verify")) {
  
              CToastMessage.getInstance().showToast(getActivity(), "Otp not Verify ! Kindly Generate Otp on Sign Up");
          }
      }
  }
  </code></pre>