Search code examples
androidandroid-service

Android multiple services matching intent


In Android, if I send an intent from my app using implicit intent, and there are two services which have a matching intent filter, which service will get invoked ?

I know for activities, the user will be asked a choice through a pop up window. How does Android make the decision in case of services ?

Thanks.


Solution

  • Quoting myself:

    In addition, what happens if there are two (or more) services installed on the device that claim to support the same <intent-filter>, but have different package names? You might think that this would fail on install, as happens with providers with duplicate authorities. Alas, it does not. Instead, once again, the first one in “wins”.

    So, if we have BadService and GoodService, both responding to the same <intent-filter>, and a client app tries to communicate to GoodService via the explicit Intent matching that <intent-filter>, it might actually be communicating with BadService, simply because BadService was installed first. The user is oblivious to this.

    Moral of this story: don't use implicit Intents with services.