Reputation: 33
I use startService() to start a new service. It will take some time before the service is ready. If I call ServiceManager.getService() immediately, it will return null. I didn't find any blocking function about this. How to know when the service is ready? Is there any blocking functions or any system message to tell me that?
The other way is put ServiceManager.getService() in a while loop, but I don't think it is good, because it will lock UI.
Upvotes: 1
Views: 580
Reputation: 41972
You should probably restructure your code to use Context#bindService
. bindService
allows you to provide a ServiceConnection
object that will have its onServiceConnected
method called when the service is ready for interaction.
Upvotes: 2