Can bindService() be made to block?

前端 未结 4 912
鱼传尺愫
鱼传尺愫 2021-02-13 15:44

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

4条回答
  •  情话喂你
    2021-02-13 15:59

    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.

自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题