I want to make a voice recorder app, which can record, even when the app is in background. So I implemented a service. I need to start it, and after it started immediately bound to it. As I suspect startService and bindService are asynchronous calls. And I experienced, when I make the calls after each other, sometimes bindService is called, when the service has not been properly started. How can I be sure that bindService runs only, when service has been started?
Share
I use the following snippet to start and bind to service:
mConnectionis a ServiceConnection instance that receives aonServiceConnectedcallback when the service is started and bound. Any time I interact with the service, I ask theServiceConnectionif the service is bound.