I have an Android application that uses a Remote Service and I bind to it with bindService()
, which is asynchronous.
The app is useless until the service is
It seems that there is a way to do this. KeyChain.java
and several Google-written classes uses a LinkedBlockingQueue
to allow synchronously bind to a service.
For example, see the method called bind
on this: https://github.com/android/platform_frameworks_base/blob/master/keystore/java/android/security/KeyChain.java
It seems to return the service object synchronously due to the use of blocking queue.
Unfortunately, as stated on the Android docs https://developer.android.com/reference/android/security/KeyChain.html, some methods throws InterruptedException
, due to the taking of element from the queue that may be interrupted when waiting.