title: Passing variable into AsyncHttpResponseHandler callback for Android
body: <p>I am using the AsyncHttpResponseHandler to gather data from a RESTful service.  The problem I am encountering is that I can not access a variable I need in the onSuccess callback.</p>
  
  <p>My code is as follows.</p>
  
  <pre><code>for (int i=0; i&lt;=count; i++) {
          requestItemsByCategory(context, categories.get(i), 10, new AsyncHttpResponseHandler() {
              @Override
              public void onSuccess(String response) {
                  loadItemsFromJsonString(context, response, categories.get(i));
              }
          });
      }
  </code></pre>
  
  <p>The context and the categories are not available in the onSuccess obviously.  I could make these global variables, but the issue would be that this is getting calle din a loop, so the onSuccess will be called a few times with no guarantee which one returns first.</p>
  
  <p>I am pretty new to Java.  In Objetive-C, you stil have access to the variables outside of the anonymous function inside the code block.  If it can't be done, I will jsut have to customize my query to pull back all the data at once, and then parse it on the client-side, which is a better solution anyway, but I would like to know if accessing items inside the callback is possible.</p>