Android – 什么是PendingIntent?

我是
Android开发的新手,我不得不使用AlarmManager重复警报.这是我第一次有机会使用PendingIntent的地方.但是在阅读完文档(
http://developer.android.com/reference/android/app/PendingIntent.html)之后,我真的很困惑PendingIntent究竟是什么.

我的问题是:

Q1. PendingIntent以什么方式’待定’?对这个问题表示歉意,但我想直观地了解PendingIntent的含义.

Q2.文件说:

A PendingIntent itself is simply a reference to a token maintained by the system describing the original data used to retrieve it. This means that, even if its owning application’s process is killed, the PendingIntent itself will remain usable from other processes that have been given it. If the creating application later re-retrieves the same kind of PendingIntent (same operation, same Intent action, data, categories, and components, and same flags), it will receive a PendingIntent representing the same token if that is still valid, and can thus call cancel() to remove it.

如何,

reference to a token maintained by the system describing the original data

我的代码在这里?

pendingIntent = PendingIntent.getBroadcast(getApplicationContext(),0,photosIntent,0);
alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME,SystemClock.elapsedRealtime(),
                           10000, pendingIntent);

Q3.我也不明白文档中的内容:

Because of this behavior, it is important to know when two Intents are considered to be the same for purposes of retrieving a PendingIntent. A common mistake people make is to create multiple PendingIntent objects with Intents that only vary in their “extra” contents, expecting to get a different PendingIntent each time. This does not happen. The parts of the Intent that are used for matching are the same ones defined by Intent.filterEquals. If you use two Intent objects that are equivalent as per Intent.filterEquals, then you will get the same PendingIntent for both of them.

额外的内容是什么?这是否涉及请求代码& getBroadcast中的标志参数(Context context,int requestCode,Intent intent,int flags)方法?

任何有关这方面的帮助将非常感激.我的在线搜索没有给我我想要的答案.另外,非常感谢你的时间.

最佳答案 Q1 – 以什么方式“待定”?

系统存储您存储在PendingIntent中的值,并允许您(或框架的其他部分)稍后查找它们,就好像查找它们的组件已经使用该信息自发地创建了一个新的Intent.

Q2 – “引用令牌”如何与我的代码相关?

Android Framework实际上并不存储您创建的PendingIntent对象;它为意图(在这种情况下,动作,数据,类型,类和类别)散列“识别信息”,并使用它来查找其余信息.您创建的文字PendingIntent对象不会被保存,它所代表的信息也会保存.

Q3 – “额外内容”是什么?

它在这里引用的“额外”是你通过putExtra()存储的可分配项目. requestCode和flags值也被保存和检索,但是当文档引用“extras”时,它意味着Intent可以用来携带附加信息的文字getExtras()Bundle.

点赞