gpt4 book ai didi

android - 使用 0 或 BIND_AUTO_CREATE 作为 bindService 的标志

转载 作者:可可西里 更新时间:2023-11-01 19:01:39 29 4
gpt4 key购买 nike

引用bindService (Intent service, ServiceConnection conn, int flags)

我可以知道,什么时候我们应该为 flags 使用 0,什么时候我们应该为 flags 使用 BIND_AUTO_CREATE?文档没有解释标志的 0 的含义。

使用 0 作为标志

的例子
// Start auto complete service.
autoCompleteServiceIntent = new Intent(AutoCompleteService.class.getName());
startService(autoCompleteServiceIntent);
bindService(autoCompleteServiceIntent, serviceConnection, 0);

BIND_AUTO_CREATE用作标志的示例

mContext.bindService(new Intent("com.android.vending.billing.InAppBillingService.BIND"),
mServiceConn, Context.BIND_AUTO_CREATE);

最佳答案

对于方法 bindService(Intent, ServiceConnection, flag) 如果使用 flag = Context.BIND_AUTO_CREATE 它将绑定(bind) service 并启动服务, 但如果使用 "0",方法将返回 true 并且不会启动服务,直到调用 startService(Intent) 来启动 服务“0” 的一种常见用法是在 Activity 连接到本地服务(如果该服务正在运行)的情况下,否则您可以启动该服务。

关于android - 使用 0 或 BIND_AUTO_CREATE 作为 bindService 的标志,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14746245/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com