theblitz
theblitz

Reputation: 6881

Prevent screen display until after fetching data

Is there any way I can go from one activity to another and delay the display of the screen on the target activity?

What I want to be able to do is to allow the target activity to fetch its required data but not to display anything until does. I want the screen of the source activity to still be visible until I am ready with the data in the second activity.

Specifically, I am using an AsyncTask to fetch the data. I know I could fetch the data in the source activity and then send it on to the target activity but this is not viable in our case.

Edit: More Info:

The whole reason I want this is because I am trying to change the structure of certain parts of the current code. At present the way it works is the the first activity gets the data and then sends it to the second activity as a bundle. This created problems when the second activity could be invoked from multiple places. It resulted in loads of duplicate code.

So, I decided to move the fetching of the data into the target activity thus cutting out any need for repeating code.

it also makes more sense for the activity to fetch its own data rather than relying on something else sending it.

Upvotes: 0

Views: 205

Answers (2)

Jeff Gortmaker
Jeff Gortmaker

Reputation: 4737

You should first make a service that runs your async task. Then, start the service from your first activity with startService(new Intent(this, UpdaterServiceManager.class));

When the task ends in the service, start the second activity.

Click here for an excellent service tutorial.

Upvotes: 1

Alex Klimashevsky
Alex Klimashevsky

Reputation: 2495

Try to use service for this purpose.

Upvotes: 0

Related Questions