First, you should never ever leave services running indefinitely. They take resources (primarily memory) from things running in the foreground.
So yes, use stopSelf() when your service is done running if that is appropriate. Exactly what you will do depends on what your service is four, there are at least three main models: (1) A background service that runs for as long as the user is interested. An example is background music playback. In this case the service is starting and stopping is controlled directly by the user. As such, while started it should have an icon in the status bar so the user knows something is going on and knows how to stop it. (2) A service that executes longer-running jobs in the background. An example would be a service that fetches recent IMAP mail every 10 minutes. In this case someone starts the service (maybe just by the alarm manager going off), and the service calls stopSelf() when it is done with that batch of work. Generally there is no need to put an icon in the status bar. (3) A service that is there for clients to call in to. An example would be something that lets clients connect to it and perform text to speech conversion of data given to it. In this case, the service is never started. It is created when the first client binds to it, and destroyed when the last client unbinds. As for threads, you should stop your threads when the service is destroyed. The threads are not, however, tied to the service in any way by the system, it is only up to you. All that a service being created means is that the system will try not to kill your overall process. On Oct 1, 3:08 pm, j <[EMAIL PROTECTED]> wrote: > Is the method Service.stopSelf() purely for saving resources (by > cleaning up memory/cpu used by the service) when all work is done? If > I don't call stopSelf(), my understanding is that my Service will > simply stick around even though it has completed all the work. Is > that correct? > > Another question is. If my service spawns off a Thread to do some > time consuming work (e.g. Network I/O) and I call stopSelf in the main > service thread before the spawn-off Thread is done with the work, > would that prevent it from completing the work? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---

