My application needs to read a file and process that information to build the list need by the activity. I can’t find a good place to do it. What I have is in the body of the activity, in a { do the work } block. If I don’t put the {…} around it, there are errors. This works, but is it the ‘correct’ way to do this? Is there a better way? This processing is only done once.
Thanks for your help
Cliff
It kind of depends on what exactly you are doing, but one common way to do lengthy processing is to create a subclass of
AsyncTaskthat does the processing in itsdoInBackgroundmethod and updates the UI in itsonPostExecutemethod. Then, you can create an instance of the AsyncTask inonCreateoronResume, call itsexecutemethod, and still have a responsive UI while the processing is occurring.That’s the way I would do it if the processing is tied to that particular Activity, such that you might want to stop the processing if the user left the Activity. If the processing were more generally useful and generated data that might be used elsewhere in the app, then I’d consider using a subclass of
ServiceorIntentService.Specifics are always helpful. If you can share more details about what you are trying to do, it will be easier to suggest the most appropriate solution.