如果清单文件中已有 intent-filter,为什么还需要 ifelse?
Why do I need ifelse if I already have intent-filter in manifest file?
好的,例如我们有一些代码 Trying to start a service on boot on Android
为什么我必须在接收器中编写 ifelse 以进行意图类型验证?
您可能正在为多个广播使用同一个接收器,或者:
- 有两个
<intent-filter>
元素,或者
- 通过对一个
<intent-filter>
元素执行多个操作,或者
- 通过对隐式
Intents
(通过 <intent-filter>
)和显式 Intents
(其中 Intent
标识 Java [=接收器的 35=])
在这些情况下,您可能需要检查传入的 Intent
以确定它是哪个广播,以便您知道如何继续。
不过,就该样本而言,我不知道他们为什么要进行 if
测试。如果他们有一个 else
,那么他们有两个基于 Intent
的不同逻辑位,这是有道理的。
好的,例如我们有一些代码 Trying to start a service on boot on Android 为什么我必须在接收器中编写 ifelse 以进行意图类型验证?
您可能正在为多个广播使用同一个接收器,或者:
- 有两个
<intent-filter>
元素,或者 - 通过对一个
<intent-filter>
元素执行多个操作,或者 - 通过对隐式
Intents
(通过<intent-filter>
)和显式Intents
(其中Intent
标识 Java [=接收器的 35=])
在这些情况下,您可能需要检查传入的 Intent
以确定它是哪个广播,以便您知道如何继续。
不过,就该样本而言,我不知道他们为什么要进行 if
测试。如果他们有一个 else
,那么他们有两个基于 Intent
的不同逻辑位,这是有道理的。