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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:45:20+00:00 2026-05-27T18:45:20+00:00

Fixed : Turns out the problem was that I was clearing the ArrayList after

  • 0

Fixed:
Turns out the problem was that I was clearing the ArrayList after passing it in to the Task, so by the time it got around to executing it, there was nothing there to send. It was working in debug because it could execute before I let it step to the next line. Lesson learned: dont pass in variables that are reused for long running tasks 🙂 Thanks to those of you who answered.

I’m trying to have user selection data sent to my webserver using an async task. Typically the user will make a selection and a string of 3 or 4 commands are sent to an AsyncTask to handle this. When I run the code, the AsyncTask is being created, but never executing the doInBackground method. Even more peculiar is that when I run in debug mode and have it step through the task creation, it works perfectly.

private class SendCommandTask extends AsyncTask< ArrayList<Command>, Void, String>{

        protected String doInBackground(ArrayList<Command>... requests){
            conn = null;
            ArrayList<Command> values = requests[0];

            for( int i = 0; i < values.size(); i++){
                try {
                    url = new URL( siteRoot + values.get(i).getEndPoint() );
                    conn = (HttpsURLConnection) url.openConnection();
                    conn.setRequestProperty("Content-Type", "application/json");
                    conn.setRequestProperty("Cookie", authCookie);
                    conn.setReadTimeout(10000 /* milliseconds */);
                    conn.setConnectTimeout(15000 /* milliseconds */);
                    conn.setDoOutput(true);

                    OutputStreamWriter os = new OutputStreamWriter(conn.getOutputStream());
                    os.write(values.get(i).getJson().toString());
                    os.flush();                     
                }catch (IOException e) {
                    e.printStackTrace();
                }
                finally{
                    conn.disconnect();              
                }
            }
            return null;
        }
    }

which is called from the UI thread via the following method:

public void sendCommand(ArrayList<Command> commands){
        new SendCommandTask().execute(commands);
    }

I’ve looked at similar threads but they just suggest using a different method, which I would rather not do since this seems to be working (in debug 🙁 )

  • 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-27T18:45:20+00:00Added an answer on May 27, 2026 at 6:45 pm

    If it seems to not be executing, something might be throwing an Exception in doInBackground, in which case the LogCat will have a stacktrace from the background thread (maybe something like siteRoot is null?)

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

Sidebar

Related Questions

Final Update : Turns out the fix to this problem is a depressing one.
I have a task that I want to run at a fixed rate. However
Fixed: See notes at bottom I am implementing a generic class that supports two
So i bet i got you curious with that title. =) Here's the scenario
I'm working with a program that writes data to fixed-size binary files that I
The problem in a nutshell is that in development mode we'd make changes to
It turns out this whole misunderstanding of the open() versus fopen() stems from a
Well this is incredibly frustrating. After being nagged by Rails that I need to
I got an OutOfMemoryException earlier and couldn't figure out what it was for. It
ETA: Turns out I may have the wrong end of the stick. Collabnet SVN

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.