Question

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.

Was it helpful?

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.

OTHER TIPS

They will look to the priority :

<intent-filter android:icon="drawable resource"
               android:label="string resource"
               android:priority="integer" >
    . . .
</intent-filter>

I arrived here because I am using Braze (was appboy) to deliver FCM messages to my app using their AppboyFirebaseMessagingService class. I now need to deliver custom events coming from my backend to my app. At first I thought I should build a new service and add it to the AndroidManifest next to the Braze service. Turns out that won't work as described by @CommonsWare.

What does work is to make a new MyFirebaseMessagingService class that is a subclass of AppboyFirebaseMessagingService and mention the MyFirebaseMessagingService in the AndroidManifest. This way both classes will see all messages. I'll have to add logic to filter for just my messages and ignore the Braze messages.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top