title: Pass Integer[] to AsyncTask - Android
body: <p>I am having trouble passing an ArrayList to a class that extends AsyncTask. The AsyncTask class, DownLoaderTask, is created in the DownloaderTaskFragment class. The code for the DownloaderTaskFragment and DownLoaderTask are below.</p>
  
  <p>The MainActivity of this application passes the ArrayList to the fragment by setting Bundle arguments. In the code below, I am retrieving the arguments, creating a new Integer[], mResourceIds, to store the values passed. </p>
  
  <p>I am confused as to how pass the Interger[] into DownLoaderTask in order to pass all values within mResourceIds. Once the parameters are passed to the DownLoaderTask, the downloadTweets() function is used to retrieve the data needed. The downloadTweets() returns a String[]. Can someone walk me through the process of passing data from an Integer[] into an AsyncTask? </p>
  
  <p>I am new to Android programming and have been wrestling with how AsyncTasks handle parameters. I greatly appreciate your any help. Thanks is advanced!</p>
  
  <pre><code>public class DownloaderTaskFragment extends Fragment {
  
      private DownloadFinishedListener mCallback;
      private Context mContext;
      static final String TAG_FRIEND_RES_IDS = "friends";
  
      @SuppressWarnings ("unused")
      private static final String TAG = "Lab-Threads";
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
  
          // Preserve across reconfigurations
          setRetainInstance(true);
  
          // TODO: Create new DownloaderTask that "downloads" data
          DownLoaderTask downLoaderTask = new DownLoaderTask();
  
  
          // TODO: Retrieve arguments from DownloaderTaskFragment
          // Prepare them for use with DownloaderTask. 
          Bundle args = getArguments();
  
          //.getIntegerArrayList returns the value associated with the given key
          ArrayList arrayList = args.getIntegerArrayList(TAG_FRIEND_RES_IDS);
  
          //Create integer array for size of arrayList passed
          Integer[] mResourceIds = new Integer[arrayList.size()];
  
          //Initialize mResourceIds with values from arrayList
          //arrayList must be cast to get Integer[], otherwise Object[] is returned
          mResourceIds = (Integer[]) arrayList.toArray(mResourceIds);
  
  
          // TODO: Start the DownloaderTask 
          downLoaderTask.execute(mResourceIds);
  
      }
  
      // Assign current hosting Activity to mCallback
      // Store application context for use by downloadTweets()
      @Override
      public void onAttach(Activity activity) {
          super.onAttach(activity);
  
          mContext = activity.getApplicationContext(); 
  
          // Make sure that the hosting activity has implemented
          // the correct callback interface.
          try {
              mCallback = (DownloadFinishedListener) activity;
          } catch (ClassCastException e) {
              throw new ClassCastException(activity.toString()
                      + " must implement DownloadFinishedListener");
          }
      }
  
      // Null out mCallback
      @Override
      public void onDetach() {
          super.onDetach();
          mCallback = null;
      }
  
  
      // TODO: Implement an AsyncTask subclass called DownLoaderTask.
      // This class must use the downloadTweets method (currently commented
      // out). Ultimately, it must also pass newly available data back to
      // the hosting Activity using the DownloadFinishedListener interface.
  
      //doInBackground
      public class DownLoaderTask extends AsyncTask&lt;Integer, Void, String[]&gt; {
  
          protected String[] doInBackground(Integer... params) {
              //Create a String[] for feed response, should be length of params passed
              //Helper method downloadTweets will return a String Array
  
              String[] feeds = downloadTweets(params);
              Log.v("doInBackground", feeds.toString());
              return feeds;
  
          }
  
          //Pass data back to hosting Activity
          protected void onPostExecute(String[] feeds) {
  
              mCallback.notifyDataRefreshed(feeds);
          }
  
      }
  </code></pre>