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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T15:45:09+00:00 2026-05-30T15:45:09+00:00

I’m using AsyncTask and some pretty common Android code to get the contents of

  • 0

I’m using AsyncTask and some pretty common Android code to get the contents of a remote webpage. Based on that returned content, I can then call another page.

http://developer.android.com/reference/android/os/AsyncTask.html

My debugging lines should print like this:

 1> StartA() 
 2> onPreExecute
 3> doInBackground 
 4> onPostExecute    Note: Code here will call EndA()
 5> EndA()
 6> 
 7> StartB() 
 8> onPreExecute 
 9> doInBackground 
10> onPostExecute     Note:  Code here will call EndB() 
11> EndB()

Is that impossible to do? I get all of the above to work… EXCEPT I get one addtional call to EndB() appearing between lines 8 and 9.

I can’t for the life of me figure out why. Nothing looks like it should call EndB() twice. And it definitely shouldn’t get called BEFORE 9 and 10.

private void StartA()
{
    Debug("StartA()");

    g_GetWhat = 1;
    DownloadWebPageTask task = new DownloadWebPageTask();
task.execute(new String[] { "http://google.com" });

}

private void EndA()
{
    Debug("EndA()");

    StartB();
}

private void StartB()
{
    Debug("StartB()");

    g_GetWhat = 2;
    DownloadWebPageTask task = new DownloadWebPageTask();
task.execute(new String[] { "http://yahoo.com" });

}

private void EndB()
{
    Debug("EndB()");
}

///////////////////////////////////////////////////

private class DownloadWebPageTask extends AsyncTask<String, Void, String> 
{
protected void onPreExecute()   
    {
        Debug("onPreExecute()");

    }

protected String doInBackground(String... urls) 
     {
    Debug("doInBackground()");
}

protected void onPostExecute(String result) 
{

    Debug("onPostExecute()"); 
    if(g_GetWhat == 1)  { EndA(); }
    if(g_GetWhat == 2)  { EndB(); }

}
}
  • 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-30T15:45:10+00:00Added an answer on May 30, 2026 at 3:45 pm

    You can only execute an AsyncTask instance once. You are actually creating two instances, but you should call it like this anyways so that it can never be recalled:

    new DownloadWebPageTask().execute(new String[] { "http://yahoo.com" });
    new DownloadWebPageTask().execute(new String[] { "http://google.com" });
    

    instead of like this:

    DownloadWebPageTask task = new DownloadWebPageTask();
    task.execute(new String[] { "http://google.com" });
    

    I think your running into the problem here:

    private void EndA()
    {
        Debug("EndA()");
    
        StartB();
    }
    

    Your value for g_GetWhat is getting changed as soon as StartB begins. So when execution returns from EndA() the next if statement evaluates to true since g_GetWhat‘s value has changed.

    if(g_GetWhat == 1)  { EndA(); }
    if(g_GetWhat == 2)  { EndB(); }
    

    The value for g_GetWhat is actually 2, which is why you see the result you are seeing. You should pass g_GetWhat into your AsyncTask when you call it and make it an instance variable of the task.

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

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.