gpt4 book ai didi

android - 服务绑定(bind)关系

转载 作者:搜寻专家 更新时间:2023-11-01 07:41:10 24 4
gpt4 key购买 nike

一个服务可以绑定(bind)n个 Activity 吗?

最佳答案

是的,它可以。

来自 https://developer.android.com/guide/components/fundamentals.html 处的文档:

Clients establish a connection to the Service object and use that connection to call into the service. The connection is established by calling Context.bindService(), and is closed by calling Context.unbindService(). Multiple clients can bind to the same service.

来自https://developer.android.com/reference/android/app/Service.html#ServiceLifecycle :

A service can be both started and have connections bound to it. In such a case, the system will keep the service running as long as either it is started or there are one or more connections to it with the Context.BIND_AUTO_CREATE flag. Once neither of these situations hold, the service's onDestroy() method is called and the service is effectively terminated. All cleanup (stopping threads, unregistering receivers) should be complete upon returning from onDestroy()

因此,一个服务可以有多个绑定(bind)。

关于android - 服务绑定(bind)关系,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2743100/

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