I am making an application that has Activity which communicates with a single service, and is used to start, stop or change settings of that service. I used a singleton approach from this tip.
My problem is that busy-waiting is not working for me and I can’t attach a listener to the service because activity gets blocked. I want the service to start or get it’s current instance at application start so I put the busy-waiting in onCreate. I’m guessing I’m doing this very wrong, so how do I do this appropriately?
Also if there is a better approach to this, please post any links or guides, cuz I’m getn confused on android developer site 😛
thanks!
Don’t do that. Use
bindService()and the local binding pattern instead, and you will be notified when the service is ready. You also get access to an API published by the service and can start using it once you are bound.