等待服务被绑定使用协程
所以我有一个绑定到服务的方法。
fun bindService() { val intent = Intent(this, BluetoothService::class.java) bindService(intent, serviceConnection, Context.BIND_AUTO_CREATE) }
里面的onCreate方法我使用这个代码:
bindService() launch { delay(500L) service = serviceConnection.serviceBinder?.getService() as BluetoothService }
有没有更优雅的方式来等待服务被绑定比使用delay()
?