我对 Android 绑定服务有一些疑问。指南: http: //developer.android.com/guide/components/bound-services.html
,关于bindService()
,说:
The `bindService()` method returns immediately without a value
但这似乎不正确,因为这里方法的签名是
public abstract boolean bindService (Intent service, ServiceConnection conn, int flags)
其中返回的布尔值描述如下:
If you have successfully bound to the service, true is returned; false is returned if the connection is not made so you will not receive the service object.
所以问题是:为什么文档说方法returns immediately without a value
?此外,在这里,绑定是通过这种方式完成的:
void doBindService() {
bindService(new Intent(Binding.this,
LocalService.class), mConnection, Context.BIND_AUTO_CREATE);
mIsBound = true;
}
而且我不明白 的含义mIsBound = true
,因为 javadoc 说 bindService() 如果绑定到服务失败,也可以返回 false。所以应该是:
void doBindService() {
mIsBound = bindService(new Intent(Binding.this,
LocalService.class), mConnection, Context.BIND_AUTO_CREATE);
}
我错了吗?