views:

354

answers:

1

Hello,

I have a comprehension question about Android Services. I have a Service that performs background http operations and a Activity that should display the current state of these http operations.

So I implementet the Binder interface and so on. I can call the bindService method and onServiceConnected of my ServiceConnnection is getting called. But as far as I know, onBind doesn't calls onStartCommand() and so onStart() of the Service is never called.

So how can I call the onStart() method of the service class and start my operations. Or how is the best way to start my operations in the service, when I also want a binding between the Activity and the Service.

+2  A: 

But as far as I know, onBind doesn't calls onStartCommand() and so onStart() of the Service is never called.

Correct.

So how can I call the onStart() method of the service class and start my operations.

Call startService() instead of bindService(). Or, don't use onStart() to "start [your] operations" and have your bound client call some other method on the service's exposed API to do that work.

CommonsWare
The latter one is what I do right now. The operations are now started by a method of the binder object. Is that "good" design or are there better solutions?thx anyway.
Masala
That sounds perfectly fine.
CommonsWare