什么是"请求code"用于在PendingIntent? [英] What's "requestCode" used for on PendingIntent?

查看:159
本文介绍了什么是"请求code"用于在PendingIntent?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景:

我通过AlarmManager用PendingIntent进行报警。

I'm using PendingIntent for alarms via AlarmManager.

的问题:

起初我以为,为了取消previous的人,我必须提供我以前用过启动报警确切的请求code。

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.

但后来我发现我错了,因为<一href="http://developer.android.com/reference/android/app/AlarmManager.html#cancel%28android.app.PendingIntent%29">cancellation API 说:

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

删除任何警报与匹配的意图。任何类型的任何警报,   其意图这个比赛(由filterEquals定义(意图)),   将被取消。

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.

在看<一href="http://developer.android.com/reference/android/content/Intent.html#filterEquals%28android.content.Intent%29">filterEquals",该文件说:

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.

所以我不明白什么是请求code是的......

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

的问题:

什么是请求code用的?

What is "requestCode" used for?

如果我创建多个报警具有相同的请求code? ?他们会互相覆盖?

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

推荐答案

1请求code,以便得到相同的悬而未决的意图以后(取消等)
2 - 是的,我想他们会得到覆盖。我将让他们独一无二的。

1- requestCode is used to get the same pending intent later on (for cancelling etc)
2- Yes, I suppose they will get override. I would keep them unique.

这篇关于什么是&QUOT;请求code&QUOT;用于在PendingIntent?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆