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

标签 android service android-manifest intentfilter android-broadcastreceiver

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

<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/

相关文章:

java - ArrayAdapter 构造函数中的 id 参数是什么资源?

android - 前台应用程序上的 startActivity 导致 onPause/onResume

Android 亚行 LogCat : ANDROID_PRINTF_LOG environment variable not working

java - Android 中两个服务如何通信?

php - Sylius:如何在自定义 ProductRepository 中注入(inject)(请求)参数?

android - 游戏中的 singleTask 或 singleInstance - Android

android - Galaxy Note 4的商店中未列出Android移动应用

java - 更改应用程序/窗口标签和图标而不更改启动器快捷方式

javascript - 在手持/智能设备上使用不同浏览器时的屏幕宽度问题

android - Android异常运行时无命令输出:'am start <应用程序/应用程序>