My application has a main activity “A”, and a secondary one, “B” (called on a button click).
Just before activity B is started, from activity A I run an async task to get xml data from a remote web service.
How do I then pass xml data to activity B? I can’t use something like
intent.putExtra("xmlData", xmlData);
since, when intent is started, xmlData is empty, yet…
Or, am I using a wrong approach? I decided to run the async task from activity A, instead than B, since I suppose I can save some time waiting for remote data in activity B…
Send the url, or unique data such as id if the url is the same, to the Activity B from A through intent.putExtra(), and fetch the data with AsyncTask as you onCreate the B activity. A progressDialog in onPreExecute might be in place as well.
Then you can reuse the Activity B if there is any similar task e.g. fetch, parse and present.