Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Unable to specify List<String> return type for AsyncTask:doInBackground

I have the following block of code based on an asynctask. I'm trying to return a List variable via return LoadFeed() and the return type of doInBackground is String. If I change the return type of doInBackground from String to List then I get an error

"The return type is incompatible with AsyncTask<String,Void,String>.doInBackground(String[])"

How do I fix this error? Please help

Thanks,

  private class DispData extends AsyncTask<String, Void, String> {
   private final ProgressDialog dialog = new ProgressDialog(MessageList.this);
   // can use UI thread here
   protected void onPreExecute() {
      dialog.setMessage("Fetching scores...");
      dialog.show();
   }


   // automatically done on worker thread (separate from UI thread)
   protected String doInBackground(final String... args) {
      return loadFeed();

   }


  // can use UI thread here
   protected void onPostExecute(final List<String> result) {
      if (dialog.isShowing()) {
         dialog.dismiss();
      }
     adapter = 
            new ArrayAdapter<String>(MessageList.this,R.layout.row,result);
     MessageList.this.setListAdapter(adapter);

   }
}
like image 355
sammydude Avatar asked Feb 26 '11 20:02

sammydude


1 Answers

Change your class definition to:

class DispData extends AsyncTask<String, Object, List<String>>

This will force the doInBackground declaration to become:

protected List<String> doInBackground(String... arg);
like image 91
Brent Worden Avatar answered Oct 13 '22 09:10

Brent Worden