title: How to return multiple List<String> via AsyncTask in android?
body: <p>I have created an <code>AsynTaskInsideActivity</code> class that extends <code>AsyncTask&lt;Void, Void, List&lt;String&gt;&gt;</code> within the <code>MainActivity</code> as an inner class. I am using this <code>AsynTaskInsideActivity</code> for getting all the records from the <code>location</code> table. This location table has following columns:</p>
  
  <ul>
  <li>location_id</li>
  <li>country</li>
  <li>state</li>
  <li>zip_code</li>
  </ul>
  
  <p>And I want to fetch records from each individual column. So, for storing every record of each individual column I created four <code>List</code> type arrays (i.e. one for each column) and successfully stored the retrieved <code>Cursor</code> data within each of them. Now, the problem is I need to return every column's records. So, to be specific how can I return those four individual <code>List</code> type arrays from a one <code>AsyncTask</code> class. Currently, I am returning only the list type array namely <code>locationId</code> which has all the location ids I fetched from location table's <code>location_id</code> column.</p>
  
  <p><strong>Questions:</strong></p>
  
  <ul>
  <li>How can I return multiple list array items from a single <code>AsyncTask</code> class? After all when we query a database, sometimes we need records from multiple columns from an individual table to process further operations. </li>
  <li>Is there any better approach that I can use to overcome this problem? or I have to believe some things are really impossible.</li>
  </ul>
  
  <p>This is what my <code>AsyncTask</code> class looks like:</p>
  
  <pre><code>public class AsyncTaskInsideActivity extends AsyncTask&lt;Void, Void, List&lt;String&gt;&gt; {
  
  private static final String CLASS_TAG = AsyncTaskInsideActivity.class.getSimpleName();
  
  @Override
  protected List&lt;String&gt; doInBackground(Void... params) {
  
      Log.v(CLASS_TAG, "AsyncTaskInsideActivity started successfully....");
  
      SoCalledDbHelper soCalledDbHelper = new SoCalledDbHelper
              (getBaseContext());
  
      //key-value pairs for inserting data into the table
      ContentValues soCalledValues = new ContentValues();
      soCalledValues.put(SoCalledContract.LocationTable.COLUMN_CITY_NAME, "Kim Kardishian");
      soCalledValues.put(SoCalledContract.LocationTable.COLUMN_STATE, "No Ass Holes");
      soCalledValues.put(SoCalledContract.LocationTable.COLUMN_ZIP_CODE, 007);
  
      //insert location data
      soCalledDbHelper.addLocationData(soCalledValues);
      //For storing the cursor data which will be retrieved by the read query.
      Cursor locationDataCursor;
  
      //Query for all the data in the location table
      locationDataCursor = soCalledDbHelper.getAllLocationData(null, null, null, null);
  
      List&lt;String&gt; sCLocationId = new ArrayList&lt;String&gt;();
      List&lt;String&gt; sCCityName = new ArrayList&lt;String&gt;();
      List&lt;String&gt; sCState = new ArrayList&lt;String&gt;();
      List&lt;String&gt; sCZipCode = new ArrayList&lt;String&gt;();
  
      if (locationDataCursor.getCount() &gt; 0) {
          //Reset the cursor location
          locationDataCursor.moveToPosition(-1);
          while (locationDataCursor.moveToNext()) {
              //Extracting data from the location cursor
              sCLocationId.add(locationDataCursor.getString
                      (locationDataCursor.getColumnIndex("_id")));
              sCCityName.add(locationDataCursor.getString
                      (locationDataCursor.getColumnIndex("city_name")));
              sCState.add(locationDataCursor.getString
                      (locationDataCursor.getColumnIndex("state")));
              sCZipCode.add(locationDataCursor.getString
                      (locationDataCursor.getColumnIndex("zip_code")));
          }
          Log.i(CLASS_TAG, "Success: Cursor has data! #Total Records: " +
                  locationDataCursor.getCount());
          for (String locationIds : sCLocationId) {
              Log.i(CLASS_TAG, "Location Id: + " + locationIds);
          }
          for (String cityNamez : sCCityName) {
              Log.i(CLASS_TAG, "City Names: + " + cityNamez);
          }
          for (String statesNames : sCState) {
              Log.i(CLASS_TAG, "State Names: + " + statesNames);
          }
          for (String zipCodes : sCZipCode) {
              Log.i(CLASS_TAG, "Zip Codes: + " + zipCodes);
          }
      } else {
          Log.w(CLASS_TAG, "Error: Cursor is empty! #Total Records: " +
                  locationDataCursor.getCount());
      }
      locationDataCursor.close();
      soCalledDbHelper.close();
      Log.v(CLASS_TAG, "AsyncTaskDbHelper ended successfully....");
      return sCLocationId;
  }
  </code></pre>
  
  <p>}</p>