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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:23:35+00:00 2026-05-18T01:23:35+00:00

I have work that needs to be done in this order: In main activity:

  • 0

I have work that needs to be done in this order:

In main activity:
-Show progress dialog
-Fetch and Parse XML from web
-dismiss dialog
-Switch to ListView activity that uses array from parsed XML in first activity

My problem is that because I have my fetching/parsing work in an ASyncTask, the main activity
immediately tries to load the new activity even the I need the fetch/parse work to be done first because it gets the data for the listView (the new activity). How can I make sure the new Activity does not load until the ASyncTask work is complete?

Here is an example of what I am working with:

   public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);


    Button submit = (Button) findViewById(R.id.submitButton);

    submit.setOnClickListener(new View.OnClickListener() {

        public void onClick(View view) {


            EditText text = (EditText) findViewById(R.id.entry);

            input = text.getText().toString();
            input = input.replace(" ", "%20");  //replace spaces with %20 for URL specification         

            WeatherRetrievalTask wt = new WeatherRetrievalTask();
        wt.execute();

            Bundle bun = new Bundle();
            bun.putParcelableArray("in", (Parcelable[])weather);

            Intent myIntent = new Intent(view.getContext(), WeeklyDisplayActivity.class);
            myIntent.putExtras(bun);
            startActivityForResult(myIntent, 0);
        }

    });
}

*Ignore this bundle work, as this is a topic for another question I need to ask…

So the startActivityForResult needs to wait until the ASyncTask is completed and the dialog is dismissed before it runs because it needs the weather data first in order to populate the list view.

  • 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-18T01:23:35+00:00Added an answer on May 18, 2026 at 1:23 am

    You should do that ‘Switch to ListView activity’ in that onPostExecute() in you ASyncTask.
    Do not write the code, that will use the result of ASyncTask just after calling its execute(), because it will execute before completing the asynctask which will be worked as another thread.
    So do the work that need use the result of asynctask doinbackground() in its onPostExecute() method

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

Sidebar

Related Questions

I have some AJAX work that brings across an additional form element that I
I am writing controls that work nice with JavaScript, but they have to work
Sometimes I have to work on code that moves the computer clock forward. In
We have a tech support website/database at work that we use to record our
I have a set of work items that are completed and I am ready
I have to work on some code that's using generic lists to store a
I have written a few MSBuild custom tasks that work well and are use
I have now 1gb ram at work(i hope that will change soon) and jboss
I have a very simple problem and a solution that will work, but I'm
I have a fairly large PHP codebase (10k files) that I work with using

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.