GVi*_*i82 3 android android-service android-activity android-service-binding
我有一些关于Android绑定服务的文章.该指南:http://developer.android.com/guide/components/bound-services.html
,约bindService(),说:
The `bindService()` method returns immediately without a value
Run Code Online (Sandbox Code Playgroud)
但这似乎不正确,因为这里方法的签名是
public abstract boolean bindService (Intent service, ServiceConnection conn, int flags)
Run Code Online (Sandbox Code Playgroud)
其中返回的布尔值描述如下:
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.
Run Code Online (Sandbox Code Playgroud)
所以问题是:为什么文档说的方法returns immediately without a value呢?而且,这里绑定是这样完成的:
void doBindService() {
bindService(new Intent(Binding.this,
LocalService.class), mConnection, Context.BIND_AUTO_CREATE);
mIsBound = true;
}
Run Code Online (Sandbox Code Playgroud)
我不明白这个意义mIsBound = true,因为javadoc说如果绑定服务失败,bindService()也可以返回false.所以它应该是:
void doBindService() {
mIsBound = bindService(new Intent(Binding.this,
LocalService.class), mConnection, Context.BIND_AUTO_CREATE);
}
Run Code Online (Sandbox Code Playgroud)
我错了吗?
文档不正确.当返回boolean为false时,这意味着不再进行建立连接的尝试.返回true表示系统尝试建立连接,这可能成功或失败.
看看这个问题的答案:"在什么情况下bindservice返回false".基本上,bindservice在找不到甚至尝试绑定的服务时返回false.
| 归档时间: |
|
| 查看次数: |
1222 次 |
| 最近记录: |