Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7166001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:20:33+00:00 2026-05-28T14:20:33+00:00

I’ve 6 different type of List results after completing AsyncTask . And the List

  • 0

I’ve 6 different type of List results after completing AsyncTask. And the List results are should be returned to an Activity. For example: List<A>, List<B>, List<C>, List<D>, List<E> and finally List<F>.

This is my AsyncTask:

public class myAsync extends AsyncTask<String, String, List> {

    private List resultList;

    @Override
    protected List doInBackground(String... params) {
        //params[0] is url
        //params[1] is type
        callAPI api = new callAPI(params[0], params[1]);
        // According to type api decides type of List and generates
        return api.getJSON(); // returns a List which already parse JSON
    }

    @Override
    protected void onPostExecute(List result) {
        // Result is here now, may be 6 different List type.
        this.resultList = result 
    }

    // returns result
    public List getResultList() { return this.resultList; }
}

I’ll call AsyncTask like this:

myAsync task = new myAsync();
task.execute(params);
List myList = task.getResultList(); // type is uncertain
Log.d("Tag", Integer.toString(myList.size());

You know, I must point out the return type (Result) between <> tags. If I choose specific type for List, it does not work for other types.

Indeed, I already tried to return List<Object> and only List types. But doesn’t worked.

I don’t want to use 6 different Async. Is it possible to solve this with an only AsyncTask? I guess I need anonymous List or something similiar not sure. Can anyone explain this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T14:20:34+00:00Added an answer on May 28, 2026 at 2:20 pm

    First, I should point out that the sequence in which you’re obtaining the list is not correct. Let me demonstrate:

    // Initialize myAsync
    myAsync task = new myAsync();
    
    // This will do work for some period of time, this statement DOES NOT 'block'
    // till myAsync completes, it will run it in the background
    task.execute(params);
    
    // This will return null because by the time you get here, task.execute most
    // likely hasn't finished yet.
    task.getResultList();
    

    Edit: Now that you’ve included what you want to do with the list result, here’s how you would modify your onPostExecute method:

    @Override
    protected void onPostExecute(List result) {
      Log.d(TAG, "The returned list contains " +result.size()+ "elements");
      // Do anything else you need to with the returned list here
    }
    

    So to summarize, if you needed to do anything else with the returned lists (besides printing their size), for example compare, print items, etc, you need to do that in the onPostExecute method.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
This could be a duplicate question, but I have no idea what search terms
I've tracked down a weird MySQL problem to the two different ways I was

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.