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值.

pendingIntent的FLAG标签:的更多相关文章

  1. dedecms flag标签属性

    头条[h] flag='h' 推荐[c] flag='c' 幻灯[f] flag='f' 特荐[a] flag='a' 滚动[s] flag='s' 加粗[b] flag='b' 图片[p] flag ...

  2. Go_16:GoLang中flag标签使用

    正如其他语言一样,在 linux 系统上通过传入不同的参数来使得代码执行不同逻辑实现不同功能,这样的优点就是执行想要的既定逻辑而不需要修改代码重新编译与打包.在 Golang 语言中也为我们提供了相应 ...

  3. GoLang中flag标签使用

    正如其他语言一样,在 linux 系统上通过传入不同的参数来使得代码执行不同逻辑实现不同功能,这样的优点就是执行想要的既定逻辑而不需要修改代码重新编译与打包.在 Golang 语言中也为我们提供了相应 ...

  4. Notification(二)——PendingIntent的flag导致数据同样的问题

    MainActivity例如以下: package cc.cu; import android.os.Bundle; import android.view.View; import android. ...

  5. 自定义控件:Flag标签

    效果图: 只有一个自定义textview.源码很简单,可以阅读下. GitHub

  6. 用alarmmanager 多次发送PendingIntent

    遇到如下问题 service中得一随机数 用alarmmanager 发送PendingIntent的时候,receiver收到的随机数不变. pendingintent传值经常获取到的值是第一次的值 ...

  7. Android消息通知(notification)和PendingIntent传值

    通知栏的自定义布局:转:http://blog.csdn.net/vipzjyno1/article/details/25248021 拓展 实现自定义的通知栏效果: 这里要用到RemoteViews ...

  8. [问题解决]同时显示多个Notification时PendingIntent的Intent被覆盖?

    情况是这样的,使用NotificationManager触发多个Notification: private Notification genreNotification(Context context ...

  9. Android控件之Notification

    Android通知就是让设备在屏幕最顶上那栏里面显示图标,当滑下通知栏之后可以看到列表状的通知选项,有些是"通知"类型的,有些是"正在运行"类型的," ...

随机推荐

  1. Eclipse4.4 安装java反编译插件Eclipse Class Decompiler

    一.在线安装方式: Eclipse Class Decompiler整合了眼下最好的2个Java反编译工具Jad和JD-Core,而且和Eclipse Class Viewer无缝集成.可以非常方便的 ...

  2. Redis学习笔记——简介及配置

    1.Redis简介 Redis概述 Redis是一个开源,先进的key-value存储,并用于构建高性能,可扩展的应用程序的完美解决方案.Redis从它的许多竞争继承来的三个主要特点:Redis数据库 ...

  3. 【2015/7/22】SqlServer卸载重装全攻略!

    请大家大声地告诉我,哪个软件最恶心. 装了之后跟在电脑里面糊了一层泥,甩都甩不干净.之前手贱,重装系统后装了sqlserver2014的试用版.可惜过了半年试用期就到了.然后重装2012.2014卸载 ...

  4. shiro配置unauthorizedUrl,无权限抛出无权限异常,但是不跳转

    在使用shiro配置无授权信息的url的时候,发现这样的一个scenario,配置好unauthorizedUrl后仍然无法跳转,然后就在网上开始找,找了原因以及解决方案 原因,先post一个源码: ...

  5. Java Spring Boot: Unable to determine jdbc url from datasource

    如果你和我一样从github或码云上下载了一个几年前别人写的demo代码,想用来做学习用.编译的时候遇到下面这样的错误,然后死命上网查各种方案,百试不灵.试尽了各种方案,就是还连接不上数据库.你可以试 ...

  6. jQuery 插件设置cookie

    对cookies的操作在当访问一个网站就无时无刻的都伴随着我们,记录着我们的一举一动,并将不危害用户隐私的信息,将以保存,这样用户就不用去从新再次操作重复的步骤,这样大大方便了客户,也增加了客户对网站 ...

  7. JavaScript的gzip静态压缩方法记录

    传统的JS压缩(删除注释,删除多余空格等)提供的压缩率有时还是不尽不意,幸亏现在的浏览器都支持压缩传输(通过设置http header的Content-Encoding=gzip),可以通过服务器的配 ...

  8. iBATIS SQL Maps

    让我们重回到车辆管理系统和张三的故事中. 在 iBATIS SQL Maps 的世界里也存在 one-to-many.many-to-one 的关系,想必你已经对这些概念驾轻就熟了.好!还是每个 Pe ...

  9. 测试RESTful API利器-Postman

    对于前端开发者而言,最需要的往往不是技术本身,其实技术都没什么难的,而最缺少的则是各种各样好的兵器,比如调试,开发工具等等. 我们这里就推荐一款前端开发的利器-Postman,它是Google Chr ...

  10. 【noip模拟题】天神下凡(贪心)

    vijos某次模拟赛原题... 处理出每个圆的一级祖先就行了... 其实没有那么麻烦,贪心即可出解. 我们将每个圆转换成线段后按左端点小右端点大的方法排序 然后维护一个栈: 对于每一个圆i 如果栈顶右 ...