gpt4 book ai didi

android - 在 list 上声明接收器和服务

转载 作者:行者123 更新时间:2023-11-30 01:12:24 25 4
gpt4 key购买 nike

我的接收者是这样声明的:

<receiver android:name=".receiverName"
android:enabled="true"/>

这是我的服务:

<service android:name=".serviceName"
android:enabled="true"/>

但我想知道:要使它们工作,我必须添加一个 <intent-filter> 吗?在每一个?

最佳答案

to make them work must I add an <intent-filter> in each one?

这取决于您使用它们的目的。

<intent-filter>是允许其他应用程序,有时是操作系统,与您的组件进行通信。这就是为什么你有一个 <activity><intent-filter>对于 MAIN行动和 LAUNCHER类别 — 主屏幕启动器知道寻找那些并让用户能够显示这些 Activity 。

因此,如果您的计划是纯粹在您自己的应用程序中使用该服务,则不需要 <intent-filter> .同样的事情也适用于你的接收器。另一方面,如果您希望其他应用程序启动该服务、绑定(bind)到该服务或向您发送广播,那么您将需要一个 <intent-filter>。 .

关于android - 在 list 上声明接收器和服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38287152/

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