Reputation: 2325
What are different between PendingIntent.FLAG_UPDATE_CURRENT and 0 in android?
var aa= PendingIntent.getService(mContext, 0, myIntent, PendingIntent.FLAG_UPDATE_CURRENT)
var bb= PendingIntent.getService(mContext, 0, myIntent, 0)
Upvotes: 8
Views: 10930
Reputation: 3349
For passing 0:
When you call:
PendingIntent pi=PendingIntent.getActivity(this, 1, i, 0);
passing 0
as the flags parameter means that you are setting no flags.
If you call:
PendingIntent pii=PendingIntent.getActivity(this, 1, i, 0);
again, and the Intent you pass matches the Intent
from the first call, then you will get back the same PendingIntent
as from the first call. "matches" means that the ACTION, DATA, CATEGORY, and COMPONENT are all the same. Extras are not considered
when matching.
If you provide different extras in the Intent for the second call, those extras will NOT be present in the PendingIntent when it is sent. The extras in the Intent from the first call will be used.
For passing PendingIntent.FLAG_UPDATE_CURRENT:
if the described PendingIntent
already exists, then keep it but replace its extra data with what is in this new Intent
.
Upvotes: 4
Reputation: 20646
If you are passing 0 as a flag you are saying that you are passing no flags to that PendingIntent
There are a difference, at least with the number.
See what is that current constant
public static final int FLAG_UPDATE_CURRENT = 134217728;
From docs FLAG_UPDATE_CURRENT
is :
Flag indicating that if the described PendingIntent already exists, then keep it but replace its extra data with what is in this new Intent. For use with getActivity(Context, int, Intent, int), getBroadcast(Context, int, Intent, int), and getService(Context, int, Intent, int).
This can be used if you are creating intents where only the extras change, and don't care that any entities that received your previous PendingIntent will be able to launch it with your new extras even if they are not explicitly given to it.
For more information about this issue check this answer
Upvotes: 1
Reputation: 24927
PendingIntent.FLAG_UPDATE_CURRENT
Based on the documentation for PendingIntent.FLAG_UPDATE_CURRENT
:
Flag indicating that if the described PendingIntent already exists, then keep it but replace its extra data with what is in this new Intent.
Usage
This can be used if you are creating intents where only the extras change, and don't care that any entities that received your previous PendingIntent will be able to launch it with your new extras even if they are not explicitly given to it.
0
Setting no flags, i.e. 0 as the flags parameter, is to return an existing PendingIntent
if there is one that matches the parameters provided. If there is no existing matching PendingIntent
then a new one will be created and returned
Upvotes: 8