I have a bit of a general question about services. Say I have a service that does this:
private void finishCountdown() {
playFinishSound();
broadcastFinishedEvent();
logFinishedEventToDatabase();
stopSelf(); // has to stop itself because it's a started service,
// and may need to run again immediately.
}
Is the stopSelf()
call always going to wait until the previous statements are done with whatever they were doing? Does it have to wait, or is simply making these calls enough to make sure they're done regardless of what happens to the service? There are some strange things happening with my app ("A SQLiteConnection object was leaked!", sound gets cut off sometimes and says "Media player finalized before being released", etc) and I'm wondering if maybe this is the reason.
If this is something I shouldn't do, then what would be the best way to have all these things (broadcast, play sound, write to database) initiated by the service (which should be stopped as soon as possible)? If I call another service to do this thing and then destroy the original service, how do I make sure the other service waits until all those things were done before stoping itself?