views:

40

answers:

1

I have a Service singleton class with static methods that I call from the same process. I call startService when my Application starts. I also call bindService, but now I am wondering if that is really necessary.

+1  A: 

It depends on whether you need to call instance methods on that service or not. StartService gets the service up and running and working on whatever Intent you sent it but you still can't interact with it because you don't have a reference to the service object. Calling bindService is what gives that reference so that you can call instance methods on it. If you don't need that, you don't need bindService.

Jere.Jones
Yes I need to call methods on that service but I am calling static methods.I guess the only reason I see bindService being useful is having the "onServiceConnected" and "onServiceDisconnected" methods being called, so that you know when your service starts and stops respectively. In my case my service is supposed to run all the time and so those methods are not so useful.Or am I missing something here?
Erdal
Your service's lifetime extends beyond onServiceConnected and onServiceDisconnected. onCreate and onDestroy are better measurements of lifetime.
Jere.Jones
that's true. so I still don't see the use for bindService in a local process.
Erdal
In your particular instance there is no use so you shouldn't use it. There are valid uses for it though.
Jere.Jones