Here is what I am trying to do :
When my application starts, it directly starts an asynchronous call to get some data from a WebService.
Then, I open a second Activity that displays that data.
Simplified code :
Activity 1 :
OnPostExecute()
{
for (int i = 0; i < jsonArray.length(); ++i)
{ JSONObject jsonTrack = jsonTrackArray.getJSONObject(i);
JSONObject jsonObject = jsonArray.getJSONObject(i);
Content content = new Content(jsonObject.getString("content"),
MyApp.contentList.add(Content);
}
}
Second Activity :
doSomething (contentList.get(0));
How can I make sure that when I try to access to contentList(0) that it has already been fetched by the AsynTask ?
You’ll probably want to either leave in user in the first activity until the operation is complete or move this logic to a service and broadcast upon completion and set some flag the second activity can check on its lifecycle creation methods.