title: Waiting for JSON response before returning the function?
body: <p>Hi folks I'm creating an android application's login/register part using the Android Volley Library. My application was working well, but the UI and logic were at the same class. So, I have separated them into two classes. My app makes requests to my NodeJS server using POST methods and gets JSON response. So I have tried to keep the POST request function in another class. </p>
  
  <p>After separating the classes, I have a problem while waiting for response. Here is the function;</p>
  
  <pre><code>public String doWebRequestLogin(Context context, boolean checkLoginForm, final Map&lt;String,String&gt; json){
          result[0] = "FREE";
          this.context = context;
  
          if(checkLoginForm){
  
              StringRequest post = new StringRequest(Request.Method.POST, loginUrl, new Response.Listener&lt;String&gt;() {
                  @Override
                  public void onResponse(String response) {
                      try  {
                          Log.d("Login Response: ",response);
                          data = response;
                          res = new JSONObject(data);
                          if (res.getString(KEY_SUCCESS) != null) {
                              int success = Integer.parseInt(res.getString(KEY_SUCCESS));
                              if (success == 1) {
                                  result[0] = "LOGGED";
                              } else if (success == 0) {
                                  result[0] = "LOGIN ERROR";
                              } else {
                                  result[0] = "INVALID POST";
                              }
                          }
                      } catch (Exception e) {
                          e.printStackTrace();
                      }
                  }
              }, new Response.ErrorListener() {
                  @Override
                  public void onErrorResponse(VolleyError error) {
                      Log.d("Response Error", error.toString());
                      result[0] = "INVALID POST";
                  }
              }){
                  @Override
                  protected Map&lt;String, String&gt; getParams() throws AuthFailureError {
                      Map&lt;String,String&gt; map = json;
  
                      return map;
                  }
              };
  
              VolleyController.getInstance(this.context).getRequestQueue().add(post);
  
          }
  
          return result[0];
      } 
  </code></pre>
  
  <p>This function returns result[0] as "FREE" at every time due to response time. How could it wait for the response and set result[0] according to the response? I need to know what happened while making requests. </p>