title: Sending/receiving an ArrayList to/from AsyncTask
body: <p>Using JSON I have trimmed the URL of an online gallery and filled an array list with the image sources, or image URLs.</p>
  
  <p>I now want to return the ArrayList back to the MainActivity so that I can then convert the ArrayList to an Array and use that Array of Image URLs to download the images and put them in a gridview.</p>
  
  <p>My problem is that I am not returning the ArrayList from the AsyncTask to the MainActivity. Any pointers would be greatly appreciated.</p>
  
  <p>Thanks for your time.</p>
  
  <p>Main Activity:</p>
  
  <pre><code>public class MainActivity extends Activity {
  
  public static ArrayList&lt;String&gt; list = new ArrayList&lt;String&gt;();
  
  @Override
  public void onCreate(Bundle savedInstanceState){
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      new myAsyncTask().execute(list);
  
      Log.v("jknfsda: ",list.get(1));
  
      //TextView line1 = (TextView) findViewById(R.id.line1);
      //for(int i=0; i&lt;list.size(); i++){
        //  line1.append(i+1 + ": " + list.get(i));
  
   }
  }
  </code></pre>
  
  <p>AsyncTask:</p>
  
  <pre><code>public class myAsyncTask extends AsyncTask&lt;ArrayList&lt;String&gt;, Void, ArrayList&lt;String&gt;&gt; {
  
  static String quellaGalleryInfo = "https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20html%20where%20url%3D%22http%3A%2F%2Fwww.quellabicycle.com%2Fgallery%22&amp;format=json&amp;callback=";
  public  static ArrayList&lt;String&gt; urlArr = new ArrayList&lt;String&gt;();
  @Override
  protected ArrayList&lt;String&gt; doInBackground(ArrayList&lt;String&gt;... list) {
  
      DefaultHttpClient httpclient = new DefaultHttpClient(new BasicHttpParams());
      HttpPost httppost = new HttpPost(quellaGalleryInfo);
      httppost.setHeader("Content-type", "application/json");
      InputStream inputStream = null;
      String result = null; // Hold all of the data from the URL
  
      try{
  
          HttpResponse response = httpclient.execute(httppost); //Response from webservice (may or may not get)
          HttpEntity entity = response.getEntity(); // all the content from the requested URL along with headers etc.
          inputStream = entity.getContent(); // get maincontent from URL
          BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"),8);// Read all data from inputStream until buffer is full
          StringBuilder theStringBuilder = new StringBuilder();//Store all the data
  
          String line = null;
  
          while((line = reader.readLine())!=null){
              theStringBuilder.append(line + "\n");
          }
          //read all the data from the buffer until nothing is left
  
          result = theStringBuilder.toString(); // everything now inside result
  
      }
  
      catch (Exception e){
          e.printStackTrace();
      }
  
      finally { //close inputstream
          try{
              if(inputStream !=null) inputStream.close();
          } catch (Exception e) {
              e.printStackTrace();
          }
  
          JSONObject jsonObject;
  
          try{
  
              Log.v("JSONParser Result: ", result);
  
              jsonObject = new JSONObject(result);//object of all the data
              JSONObject queryJSONObject = jsonObject.getJSONObject("query");//get query objects
              JSONObject resultsJSONObject = queryJSONObject.getJSONObject("results");//get results object inside of query object
              JSONObject bodyJSONObject = resultsJSONObject.getJSONObject("body");
              JSONArray divJSONArray = bodyJSONObject.getJSONArray("div");
              JSONObject div_position_zero = divJSONArray.getJSONObject(0);
              JSONArray ulJSONArray = div_position_zero.getJSONArray("ul");
              JSONObject ul_position_two = ulJSONArray.getJSONObject(2);
              JSONArray liJSONArray = ul_position_two.getJSONArray("li");
  
              for(int i=0; i &lt; liJSONArray.length(); i++){
                  JSONObject li_position = liJSONArray.getJSONObject(i);
                  JSONObject a_JSONObject = li_position.getJSONObject("a");
                  JSONObject imgJSONObject = a_JSONObject.getJSONObject("img");
                  urlArr.add(imgJSONObject.getString("src"));//final object where data resides
              }
  
              for(String item : urlArr){
  
                  Log.v("JSONParser list items: ", item);
  
              }
  
  
          } catch (JSONException e) {
              e.printStackTrace();
          }
      }
      return null;
  }
  
  
  //protected void onPostExecute(ArrayList&lt;String&gt;... list){
    //  if(MainActivity.list.size()&gt;0){
      //    MainActivity.list.clear();
  
      //for(int i =0; i&lt;urlArr.size();i++){
        //  Log.v("ope urlarr: ", urlArr.get(i));
  
          //MainActivity.list.add(urlArr.get(i));
      //}
      }
  
  
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p>It works up until here 
  Log.v("JSONParser list items: ", item); 
  and then my LogCat just goes blank. </p>
  
  <p>Thanks again.</p>