I have an android application that I'm developing, and the application really just a few tasks and then exits when its done. Right now I have an activity that displays a button, and when I press it, it runs the task.

Basically I just want an application where launching it just runs that task and closes the application. Is the way to go about this just to create an activity that doesn't create a GUI? Right now my manfiest xml file also lists

2 Answers
2

You could start a service from your activity that does the actual work, and then call finish(). That would close the activity, and won't display a GUI. Make sure the service executes your task in a new thread, because otherwise it will still block the UI thread. Also keep in mind that a service could be restarted, so be ready to handle this.

Can I just do the the work from the activity and call finish?
–
Jeff StoreyMar 12 '12 at 3:36

You could, but it's neither much easier, nor more reliable. You need to start up a new thread to do the work, but once you call finish(), the activity (process) will go in the background, and the chance that it will be killed once the users starts something else increases. The service is designed to work in the background, so it will have a greater chance to finish the work.
–
Nikolay ElenkovMar 12 '12 at 4:10