title: Getting response out of AsyncHttpClient
body: <p>Im using this lib: <a href="http://loopj.com/android-async-http/" rel="nofollow noreferrer">http://loopj.com/android-async-http/</a> to make all my requests &amp;&amp; The biggest thing currently making my code messy is that I havent been able to successfully get my Async Http Request Responses out of onSuccess() so that the data is available to the rest of the class freely. Up till this point I have been parsing all my request responses inside the curlys of my responsehandlers onSuccess(){}</p>
  
  <p>I came across this post on Stack:<a href="https://stackoverflow.com/questions/12575068/how-to-get-the-result-of-onpostexecute-to-main-activity-because-asynctask-is-a">How to get the result of OnPostExecute() to main activity because AsyncTask is a separate class?</a></p>
  
  <p>but have yet to get it to work with this lib. </p>
  
  <pre><code>import com.loopj.android.http.*;
  
  public class TwitterRestClient {
    private static final String BASE_URL = "http://api.twitter.com/1/";
  
    private static AsyncHttpClient client = new AsyncHttpClient();
  
    public static void get(String url, RequestParams params, AsyncHttpResponseHandler responseHandler) {
        client.get(getAbsoluteUrl(url), params, responseHandler);
    }
  
    public static void post(String url, RequestParams params, AsyncHttpResponseHandler responseHandler) {
        client.post(getAbsoluteUrl(url), params, responseHandler);
    }
  
    private static String getAbsoluteUrl(String relativeUrl) {
        return BASE_URL + relativeUrl;
    }
  }
  
  
  
  
  import org.json.*;
  import com.loopj.android.http.*;
  
  class TwitterRestClientUsage {
      public void getPublicTimeline() throws JSONException {
          TwitterRestClient.get("statuses/public_timeline.json", null, new JsonHttpResponseHandler() {
              @Override
              public void onSuccess(JSONArray timeline) {
                  // Pull out the first event on the public timeline
                  JSONObject firstEvent = timeline.get(0);
                  String tweetText = firstEvent.getString("text");
  
                  // Do something with the response
                  System.out.println(tweetText);
              }
          });
      }
  }
  </code></pre>