使用0或BIND_AUTO_CREATE作为bindService的标志 [英] Use 0 or BIND_AUTO_CREATE for bindService's flag
问题描述
通过引用我是否知道,什么时候应该将0用于 flags
,何时应该将 BIND_AUTO_CREATE
用于 flags
?该文档没有解释标志0的含义.
May I know, when should we use 0 for flags
, and when should we should we use BIND_AUTO_CREATE
for flags
? The documentation doesn't explain what is the meaning of 0 for flags.
// Start auto complete service.
autoCompleteServiceIntent = new Intent(AutoCompleteService.class.getName());
startService(autoCompleteServiceIntent);
bindService(autoCompleteServiceIntent, serviceConnection, 0);
将 BIND_AUTO_CREATE
用作 flags
的示例
Example for using BIND_AUTO_CREATE
as flags
mContext.bindService(new Intent("com.android.vending.billing.InAppBillingService.BIND"),
mServiceConn, Context.BIND_AUTO_CREATE);
推荐答案
对于方法 bindService(Intent,ServiceConnection,flag)
,如果使用了 flag = Context.BIND_AUTO_CREATE
将绑定 service
并启动该服务,但是如果使用"0"
,则该方法将返回true,并且不会启动服务,直到进行诸如 startService(Intent)
之类的调用以启动 service 代码>.
"0"
的普遍用法之一是,如果有活动连接到本地服务(如果该服务正在运行),则可以启动该服务.
For method bindService(Intent, ServiceConnection, flag)
if flag = Context.BIND_AUTO_CREATE
is used it will bind the service
and start the service,
but if "0"
is used, method will return true and will not start service until a call like startService(Intent)
is made to start the service
.
One of the common use of "0"
is in the case where an activity to connect to a local service if that service is running, otherwise you can start the service.
这篇关于使用0或BIND_AUTO_CREATE作为bindService的标志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!