I have a service that is designed to run in the foreground and allow clients to bind to it. It is similar to a music foreground service (described here) that plays music and allows an app to bind to it and control actions like pause and play.
Specifically, I want the service to be in the foreground before it does any work as a result of a client binding to it.
I am aware of the BIND_AUTO_CREATE flag but that only creates the service; it does not put the service into the started state and also doesn't put it into the foreground.
I am also aware that (not true)bindService returns a boolean indicating if the service is already created or not and that it can be used to start the service if it hasn't already, then bind to it.
However, that allows for race conditions to creep in and also forces the client to keep track of service's state. I'd prefer for the service, in the onBind method, to start and put itself in the foreground. This leads me to the question.
Can a bound service start itself. Or in otherwords, can a service (named MyService) successfully call startService(new Intent(this, MyService.class));?