Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating different PendingIntent objects - request code vs. different Intent

In my code, i am creating various PendingIntent objects using getBroadcast().

My application needs to represent a few different types of PendingIntents, and for this reason i create the underlying Intent with a different action string (unique per PendingIntent).

My question is - does it make any difference to differentiate the pending intents by the request code, or stick with the technique i am doing now ?

Example:

What i'm doing now:

Intent intent = new Intent(Receiver.class);
intent.setAction("unique.name.here");

PendingIntent.getBroadcast(this, 0, intent, flags);

Other technique:

Intent intent = new Intent(Receiver.class);
PendingIntnt.getBroadcast(this, uniqueId, intent, flags);

Is there any reason why should i pick one technique over the other?

like image 865
lysergic-acid Avatar asked Mar 25 '26 12:03

lysergic-acid


1 Answers

Use whatever technique you want that works for you. Sometimes you need a unique PendingIntent but you can't use a unique action because the action is used for some other purpose (Intent resolution or whatever).

like image 131
David Wasser Avatar answered Mar 27 '26 00:03

David Wasser



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!