title: Return data from AsyncTask class
body: <p>How do I get the data from my AsyncTask?  My MainActivity is calling the DataCall.getJSON function  that triggers the AsyncTask but I am not sure how to get the data back to the original Activity.</p>
  
  <p><strong>MainActivity with call to DataCall that should return a string and save it in <code>state_data</code></strong></p>
  
  <pre><code>String state_data =  DataCall.getJSON(spinnerURL,spinnerContentType); 
  </code></pre>
  
  <p><strong>DataCall:</strong></p>
  
  <pre><code>public class DataCall extends Activity {
      private static final String TAG = "MyApp";
  
  
      private class DownloadWebPageTask extends AsyncTask&lt;String, Void, String&gt; {
  
  
          protected String doInBackground(String... urls) {
              String response = "";
              for (String url : urls) {
                  DefaultHttpClient client = new DefaultHttpClient();
                  HttpGet httpGet = new HttpGet(url);
                  try {
                      HttpResponse execute = client.execute(httpGet);
                      InputStream content = execute.getEntity().getContent();
  
                      BufferedReader buffer = new BufferedReader(
                              new InputStreamReader(content));
                      String s = "";
                      while ((s = buffer.readLine()) != null) {
                          response += s;
                      }
  
                  } catch (Exception e) {
                      e.printStackTrace();
                  }
              }
              return response;
          }
  
  
          protected void onPostExecute(String result) {
              //THIS IS WHERE I NEED TO RETURN MY DATA TO THE MAIN ACTIVITY. (I am guessing)
          }
  
          }
  
      public void getJSON(String myUrlString, String contentType) {
          DownloadWebPageTask task = new DownloadWebPageTask();
          task.execute(new String[] { "http://www.mywebsite.com/" + myUrlString });
  
      }
  
  }
  </code></pre>