Reputation: 10510
I am just starting to learn Android Development. I have a method that loads an external XML file, and parses the data. How do I tell the caller that the data is parsed and ready? Should I and a callback argument to the method? Or should the caller register to listen to some kind of event, that I can fire when the data is ready?
A code example or links would be great.
Upvotes: 1
Views: 244
Reputation: 1630
You can always start your activity when the previous work... here parsing the data is done. Alternatively use a broadcast and let your application have a broadcast receiver and notify your application.
Upvotes: 0
Reputation: 2477
If the task is not very complex, you could also use the usual threading approach.
Upvotes: 2
Reputation: 16603
You can use ASyncTask class for this kind of problem. It has several methods that you can override that will suit you for most of the tasks you need - for example it has pre-execution method and progress update method.
Here is a tutorial for using ASyncTask in an app.
Upvotes: 4