0

Ok, for example we have some code like Trying to start a service on boot on Android Why must I write ifelse in receiver for intent type validation?

Community
  • 1
  • 1
glnix
  • 126
  • 1
  • 1
  • 8

1 Answers1

1

You may be using the same receiver for multiple broadcasts, either:

  • by having two <intent-filter> elements, or
  • by having multiple actions for one <intent-filter> element, or
  • by using the receiver for both implicit Intents (via the <intent-filter>) and explicit Intents (where the Intent identifies the Java class of the receiver)

In those cases, you might need to examine the incoming Intent to see which broadcast it is, so you know how to proceed.

In terms of that sample, though, I do not know why they have that if test. If they had an else, so they had two different bits of logic based on the Intent, it would make sense.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491