Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
333 views
in Technique[技术] by (71.8m points)

android - What's "requestCode" used for on PendingIntent?

Background:

I'm using PendingIntent for alarms via AlarmManager.

The problem:

At first I thought that in order to cancel previous ones, I must provide the exact requestCode that I've used before to start the alarm.

But then I've found out I was wrong, as the cancellation API says:

Remove any alarms with a matching Intent. Any alarm, of any type, whose Intent matches this one (as defined by filterEquals(Intent)), will be canceled.

looking at "filterEquals", the documentation says:

Determine if two intents are the same for the purposes of intent resolution (filtering). That is, if their action, data, type, class, and categories are the same. This does not compare any extra data included in the intents.

so I don't get what the "requestCode" is for...

The question:

What is "requestCode" used for?

What if I create multiple alarms with the same "requestCode" ? do they override each other?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
  1. requestCode is used to retrieve the same pending intent instance later on (for cancelling, etc).
  2. Yes, my guess is the alarms will override each other. I would keep the request codes unique.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...