通过参考bindService(意图服务、ServiceConnection conn、int 标志) http://developer.android.com/reference/android/content/Context.html#bindService%28android.content.Intent,%20android.content.ServiceConnection,%20int%29
我想知道什么时候应该使用 0flags
,我们什么时候应该使用BIND_AUTO_CREATE
for flags
?该文档没有解释标志 0 的含义。
使用 0 作为的示例flags
// Start auto complete service.
autoCompleteServiceIntent = new Intent(AutoCompleteService.class.getName());
startService(autoCompleteServiceIntent);
bindService(autoCompleteServiceIntent, serviceConnection, 0);
使用示例BIND_AUTO_CREATE
as flags
mContext.bindService(new Intent("com.android.vending.billing.InAppBillingService.BIND"),
mServiceConn, Context.BIND_AUTO_CREATE);
对于方法bindService(Intent, ServiceConnection, flag)
if flag = Context.BIND_AUTO_CREATE
使用它会绑定service
并启动服务,
但如果"0"
使用时,方法将返回 true 并且不会启动服务,直到像这样的调用startService(Intent)
是为了开始service
。
常见的用途之一是"0"
是指连接到本地服务的活动(如果该服务正在运行),否则您可以启动该服务。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)