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 was wondering if there is an event delegate concept that is present in android by which i can make my xml parsing class respond to my activity when it is over.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With