title: How to create a proper Volley Listener for cross class Volley method calling
body: <p>I aim to call Volley from another class in, a very succinct, modular way ie:</p>
  
  <pre><code>            VolleyListener newListener = new VolleyListener();
              VolleySingleton.getsInstance().somePostRequestReturningString(getApplicationContext(), newListener);
              JSONObject data = newListener.getResponse();
  </code></pre>
  
  <p>But am having allot of trouble getting the listener portion to work so as to be able to access the resulting data from a method such as </p>
  
  <pre><code>newListener.getResponse();
  </code></pre>
  
  <p>There are a few questions on this site that generally outline how to set up a volley call from another class, such as: <a href="https://stackoverflow.com/questions/28172496/android-volley-how-to-isolate-requests-in-another-class">Android Volley - How to isolate requests in another class</a>. I have had success getting the method call to work, but to now get that data into the present class for usage has caused trouble.</p>
  
  <p>I have the action within my <code>VolleySingleton</code> class as:</p>
  
  <pre><code>public void somePostRequestReturningString(final Context context,final VolleyListener&lt;String&gt; listener) {
  
          final String URL = "http://httpbin.org/ip";
  
          JsonObjectRequest set = new JsonObjectRequest(Request.Method.GET, URL, ((String) null),
                  new Response.Listener&lt;JSONObject&gt;() {
                      @Override
                      public void onResponse(JSONObject response) {
  
                          listener.outPut = response.toString();
                          //Toast.makeText(context, response.toString(), Toast.LENGTH_LONG).show();
                      }
                  },
                  new Response.ErrorListener() {
                      @Override
                      public void onErrorResponse(VolleyError error) {
                          Log.d("Error.Response", error.toString());
                      }
                  }
          );
  
          mRequestQueue.add(set);
  }
  </code></pre>
  
  <p>and within the listener class:</p>
  
  <pre><code>public class VolleyListener {
      public static String outPut;
  
      private static Response.Listener&lt;String&gt; createSuccessListener() {
          return new Response.Listener&lt;String&gt;() {
              @Override
              public void onResponse(String response) {
                  outPut = response;
              }
          };
      }
  }
  </code></pre>
  
  <p>How can I configure this to work and allow Volley calls and data retrieval from another class, particularly how to build callbacks correctly?</p>