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.
You should probably restructure your code to use
Context#bindService.bindServiceallows you to provide aServiceConnectionobject that will have itsonServiceConnectedmethod called when the service is ready for interaction.