Hey guys, I could only find 1 thread on this, and it didn’t really answer my question, so I’m asking for myself.
My application is downloading and parsing an rss file, and I’ve obviously decided to do this in a background task. I chose AsyncTask, and I’m trying to get it to start the download and then bring up the list view for the rss feed. From there I’d like the AsyncTask from the other activity to pass the now parsed information to the new list view activity as it loads it. I can’t figure out how to pass a reference to my AsyncTask object to my new activity without implementing parcelable and adding it to the bundle which would be a huge mess I think. Is there a better way to do this?
I’ve also seen other people recommend starting a service. What would be the advantages to doing it this way? Thanks!
~Scott
This is exactly the case for using a service. An AsyncTask is for doing things on a UI thread (a convenience class really).
What you are doing should go on in a service, because you don’t necessarily care about the UI thread since you are not going to be displaying in the same activity.
Here is how you should go about doing this:
1) create a service and do the processing of the RSS feed
2) inside the service you should store your results in a database with the ContentResolver
3) Have your ListAdapter in your ListActivity listen for changes on the same CONTENT_URI as your service is updating. This will automatically update your list as the rows get added or deleted, without any ANRs since it’s all on the background thread
Some other advantages is that you can sync in the background without having your UI to be open at all. This could be very useful for a RSS application since you don’t always want to wait for a user to initiate a sync.