PendingIntent是一个特殊的Intent,实际上它像一个邮包,其中包裹着真正的Intent,当邮包未打开时,Intent是被“挂起”的,所以并不执行,

只有当邮包拆开时才会执行。它与Intent的区别在于:Intent 是及时启动,intent 随所在的activity 消失而消失。

  PendingIntent 可以看作是对intent的包装,通过getActivity,getBroadcast ,getService来得到pendingintent的实例,当前activity并不能马

上启动它所包含的 Intent, 而是在外部执行 pendingintent时再调用 Intent。

  正由于pendingintent中 保存有当前App的Context,使它赋予外部App一种能力,使得外部App可以如同当前App一样的执行pendingintent里

的 Intent, 就算在执行时当前App已经不存在了,也能通过存在pendingintent里的Context照样执行Intent。常和alermanger 和notificationmanager

一起使用。

  Intent一般是用作Activity、Sercvice、BroadcastReceiver之间传递数据,而Pendingintent,一般用在 Notification上,可以理解为延迟执行的

intent,PendingIntent是对Intent一个包装。

  FLAG_ONE_SHOT:this PendingIntent can only be used once. If set, after send() is called on it, it will be automatically canceled

for you and any future attempt to send through it will fail.

  FLAG_NO_CREATE:if the described PendingIntent does not already exist, then simply return null instead of creating it.

  FLAG_CANCEL_CURRENT:if the described PendingIntent already exists, the current one is canceled before generating a new one.

You can use this to retrieve a new PendingIntent when you are only changing the extra data in the Intent; by canceling the previous

pending intent, this ensures that only entities given the new data will be able to launch it. If this assurance is not an issue, consider

FLAG_UPDATE_CURRENT.

  FLAG_UPDATE_CURRENT: if the described PendingIntent already exists, then keep it but its replace its extra data with what is in

this new Intent. 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.

  

  上面4个flag中最经常使用的是FLAG_UPDATE_CURRENT,因为描述的Intent有更新的时候需要用到这个flag去更新你的描述,否则组件在下次事件

发生或时间到达的时候extras永远是第一次Intent的extras。

  使用FLAG_CANCEL_CURRENT也能做到更新extras,只不过是先把前面的extras清除,另外FLAG_CANCEL_CURRENT和

FLAG_UPDATE_CURRENT的区别在于是否创建一个新的Intent,FLAG_UPDATE_CURRENT能够创建一个新的Intent,而FLAG_CANCEL_CURRENT

则不能,只能使用第一次的Intent。

  另外两flag就比较少用,利用FLAG_ONE_SHOT获取的PendingIntent只能使用一次。利用FLAG_NO_CREAT获取的 PendingIntent若描述的

Intent不存在则返回NULL值.

最新文章

  1. Security9:查询Login被授予的权限
  2. Google疯了,竟然这样!
  3. android上下文菜单
  4. spring知识大全(4)
  5. df卡住问题解决
  6. sizeof既是关键字,又是运算符(操作符),但不是函数!
  7. jsformat插件
  8. Ubuntu安装Burg
  9. QQ上传大文件为什么这么快
  10. JSP:useBean,setProperty的使用
  11. 【转】 Java 多线程之一
  12. linux权限掩码
  13. AFN的坑--NSCachedURLResponse缓存
  14. C++ Primer 学习笔记_62_重载操作符与转换 --调用操作符和函数对象
  15. android-sdk-windows下载版
  16. Web API框架学习——路由(一)
  17. VBR与CBR的区别是什么?
  18. 关于bash
  19. Jmeter学习系列----2 录制脚本
  20. 在word中批量更改Mathtype公式的格式

热门文章

  1. ajax——优化0126(增删改查:添加查看详情,返回结果类型为JSON型,在窗口显示)
  2. 实现cell显示一个删除button
  3. yum whatprovides host 根据命令查找包
  4. mysql实现经纬度计算两个坐标之间的距离
  5. [android] AndroidManifest.xml【 manifest -> uses-permission】
  6. 具有全球唯一性,相对于internet,IP为逻辑地址
  7. Yii2.0实现微信公众号后台开发
  8. systemd新的系统管理方案
  9. JQuery------图片幻灯片插件
  10. shrink-to-fit(自适应宽度)