A comment about the statement: ----------------------------- We deliberately don't have an API to check whether a service is running because, nearly without fail, when you want to do something like that you end up with race conditions in your code. ---------------------------- The problem is that if the service is already running and you issue a call to bind to that service, I didn't get a callback to my ServiceConnection onServiceConnected method. In my case, I was using a semaphore to indicate that the service was actually connected before making a call on that service. Since it's not called, the semaphore is not released and code doing the semaphore acquire will not proceed. That's an example of why one sometimes one might want to check if the service is already running. I don't know the developer's team rationale, but it's probably bad form that sometimes you don't get a callback to the onServiceConnected when you issue a call to bind to a service; even if that service was already running. I used the semaphore because, without it I noticed a race condition between using the service and the service actual being available from the time after I issued a call to bind to that service. So you solve one problem but create another. Something to think about.
On Thursday, December 27, 2007 at 8:20:57 PM UTC-8, hackbod wrote: > On Dec 26, 8:48 pm, "ho...@helloandroid.com" <ho...@helloandroid.com> > wrote: > > You could track the state of the service using some kind of persistant > > variable (ie., preferences or sql lite) that you can set on onCreate() > > and onDestroy() in your service, or you could try to see if you can > > see the process running using something like this: > http://davanum.wordpress.com/2007/12/18/android-task-manager-primitiv... > > It would be best to not depend on knowing the name of the process that > your service is running in. You can bind to a service without causing > it to start; by doing so, you will be told as the service is created > and destroyed. > > If your client and server code is part of the same .apk and you are > binding to the service with a concrete Intent (one that specifies the > exact service class), then you can simply have your service set a > global variable when it is running that your client can check. > > We deliberately don't have an API to check whether a service is > running because, nearly without fail, when you want to do something > like that you end up with race conditions in your code. > -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to android-developers+unsubscr...@googlegroups.com. To post to this group, send email to email@example.com. Visit this group at https://groups.google.com/group/android-developers. To view this discussion on the web visit https://groups.google.com/d/msgid/android-developers/d3de0c03-af76-4b16-8f30-f64d71893316%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.