title: Handle callbacks in my library
body: <p>I have written an android library that does network calls to various websites and returns the necessary content. I am using Volley library which has callbacks like <code>onResponse</code> and <code>onFailure</code>. Initially this library was an app and was later changed to an library.</p>
  
  <p>When it was an app I could handle the callbacks easily. Whenever the callback happens I call the required functions from there but now when I import as the library and try to use it the control returns from the library as soon as I call it and the call back is not doing anything.</p>
  
  <pre><code>public void sendForVerification(final String Response, final String Secret, final String Name) {
      StringRequest stringRequest = new StringRequest(Request.Method.POST, url, new Response.Listener&lt;String&gt;() {
          @Override
          public void onResponse(String response) {
              flag = true;
          },
          new Response.ErrorListener() {
              @Override
              public void onErrorResponse (VolleyError error){
                  flag = false;
              }
          }})  {
              @Override
              protected Map&lt;String, String&gt; getParams () throws AuthFailureError {
                  HashMap&lt;String, String&gt; params = new HashMap&lt;&gt;();
                  params.put("secret", Secret);
                  params.put("response", Response);
                  return params;
              }
          };
          requestQueue.add(stringRequest);
      }
  }
  </code></pre>
  
  <p>When this code was a part of the app instead of returning the flag value I would call an appropriate function to handle the result. Now whenever I call these functions the value of flag is returned before the callback is done and this is causing some problem.</p>
  
  <p>My question is how can I warp this around a callback so that the app that uses this library will be notified when the network call is done?</p>