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 8816949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:44:11+00:00 2026-06-14T04:44:11+00:00

I have created an AsyncTask which read JSONArray in the doInBackground Method and return

  • 0

I have created an AsyncTask which read JSONArray in the doInBackground Method and return an ArrayList of custom Items (ArrayList). Before this, in the onPostExecute method i move the ArrayList charged in the AsyncTask to another ArrayList of the Main thread, but i think that my AsyncTask never ends and still working. Here I put my code:

Here the AsyncTask:

private class ReadJSONTask extends AsyncTask<Void, Void, ArrayList<Item>>{

        @Override
        protected ArrayList<Item> doInBackground(Void... params) {
            // TODO Auto-generated method stub
            ArrayList<Item> auxList = new ArrayList<Item>();
            LoadData(auxList); //Method that reads JSON and load information in the ArrayList
            return auxList; // Return ArrayList
        }

        @Override
        protected void onPostExecute(ArrayList<Item> result) {
            // TODO Auto-generated method stub

            Log.i("OnPostExecute", String.valueOf(result.size()));  //The size of the array
            listMain = result; // Move the data of the AsyncTask to the main Thread

            Log.i("OnPostExecute", String.valueOf(listaComic.size()));  //The size of the ArrayList I use in the Main Thread
        }

    }

Here the call to the AsyncTask in the Main Thread:

if (isOnline()){    //Return true if there is internet connection
    ReadJSONTask task = new ReadJSONTask();
    task.execute();

    Log.i("Main Thread - listMain Size", String.valueOf(listMain.size())); //Never executed

    //This for loop its only for debug purposes, never executed
    for (Item item : listMain){ 
        Log.i("Items", item.toString());
    }
}

In the log i see that all Log in the onPostExecute() method are printed, but nothing from the Main Thread.

I don’t know where is the error to fix it, i have been working on it 2 days and searching in forums, here in StackOverflow and i can’t fix that :S

  • 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-06-14T04:44:12+00:00Added an answer on June 14, 2026 at 4:44 am

    As name indicates AsyncTask is asynchronous, but you for some reason expects execute() to be blocked unless async task ends, which is wrong. Your code works fine and I expect listMain to simply be empty and once execute() fires asynctask, for would show nothing because async task is not done yet. You should rework your app logic, so async task could tell “main thread” it finished. I.e. move your for loop to separate method and call it from onPostExecute().

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

Sidebar

Related Questions

I have an AsyncTask which calls my LocationHandler class method getLocation() which runs a
I have created an asynchronous task like this: private class LongOperationcheckall extends AsyncTask<String, String,
I am trying to create downloading progress. I have my class which extends AsyncTask:
I have created a custom post type named People. I have created a page
I have a listview which is filled by AsyncTask and I am trying to
I have a listview in which i wanted to have custom typeface e.g. Arial.
this is the current state/situation: I have an Activity which binds a Service which
I have created an application having tab activity which in turn has 5 different
I have created an app which retrieves the data from a url using xml
In my Android application I have an Observable Data class, which contains a method

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.