I have a activity which calls a webservice and does xml parsing. i want my activity to wait for the xml parsing class to execute and then i want my acitvity to continue. i w
Yes, there's. You will love the ResultReceiver
class. To create one you will need to pass a Handler
(created inside the activity), and override the onReceiveResult
method.
So, what you do is sending a reference of the ResultReceiver
to the service (using the Intent
extras), and when the XML parsing is done, you call the send
method from the Service
. That way your activity will be notified that the XML parsing has finished.
There's a Google IO video where this technique is explained. You can also download the slides used in the conference.
If you want example code, take a look at the iosched app. It will teach how to create a ResultReceiver
proxy that will help you deal with configuration changes (e.g. the device rotation changes)... because, as you know, when that happens the UI is recreated, thus it could cause memory leaks (you know, the service will be pointing to non-existing UI elements).