0

I download a RSS Feed and then parse it in a class, the rssfeed is saved as a custom object; however the code blocks as the feed is relatively big and the Android typically works only on EDGE.

I want to put the downloading of the file into an AsyncTask with an indefinite progress dialog.

I also want to be able to access the rssfeed object after its downloaded in the ASynctask from within the Main Thread. How do I reference it?

Robert de Klerk
  • 624
  • 3
  • 12
  • 24
  • 1
    http://developer.android.com/reference/android/os/AsyncTask.html – waqaslam Feb 13 '12 at 14:47
  • I had a look at that before already, what I just dont understand I guess it the part about being invoked from the main thread. Does that mean that after I call the execute() method of ASyncTask I call the onPostExecute() from the main UI as well? – Robert de Klerk Feb 13 '12 at 14:50
  • Consider this answer: http://stackoverflow.com/questions/4489399/asynctask-where-return-value-of-doinbackground-goes – Dmytro Danylyk Feb 13 '12 at 14:54
  • you never call the override method. All you need to call is `execute()` method – waqaslam Feb 13 '12 at 14:55

1 Answers1

1

When you build an AsyncTask, the third generic argument is the Result, and when you execute the asyn task, you can call get to retrieve the Result object. Depending on what you need to do with the object on the main thread, you can also override the AsyncTask's onPostExecute method which will be run on the main thread after doInBackground completes. This is probably the best bet, to override onPostExecute on the AsyncTask.

Nick Campion
  • 10,479
  • 3
  • 44
  • 58
  • would the get() be a blocking call? `RssFeedObject rfo;` `ASyncTask task = new ASyncTask;` `task.execute();` `rfo = task.get();` Would that not cause the UI Thread to hang until the rssfeedObject is complete? – Robert de Klerk Feb 13 '12 at 15:22
  • Yes, calling `get()` from the UI thread will make it wait until the task is complete. – dave.c Feb 13 '12 at 15:25
  • 1
    If you don't want to block, your best bet is to review overriding onPostExecute. That gets you main thread execution without blocking. – Nick Campion Feb 13 '12 at 15:30