pendingIntent的FLAG标签:
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标签:的更多相关文章
- dedecms flag标签属性
头条[h] flag='h' 推荐[c] flag='c' 幻灯[f] flag='f' 特荐[a] flag='a' 滚动[s] flag='s' 加粗[b] flag='b' 图片[p] flag ...
- Go_16:GoLang中flag标签使用
正如其他语言一样,在 linux 系统上通过传入不同的参数来使得代码执行不同逻辑实现不同功能,这样的优点就是执行想要的既定逻辑而不需要修改代码重新编译与打包.在 Golang 语言中也为我们提供了相应 ...
- GoLang中flag标签使用
正如其他语言一样,在 linux 系统上通过传入不同的参数来使得代码执行不同逻辑实现不同功能,这样的优点就是执行想要的既定逻辑而不需要修改代码重新编译与打包.在 Golang 语言中也为我们提供了相应 ...
- Notification(二)——PendingIntent的flag导致数据同样的问题
MainActivity例如以下: package cc.cu; import android.os.Bundle; import android.view.View; import android. ...
- 自定义控件:Flag标签
效果图: 只有一个自定义textview.源码很简单,可以阅读下. GitHub
- 用alarmmanager 多次发送PendingIntent
遇到如下问题 service中得一随机数 用alarmmanager 发送PendingIntent的时候,receiver收到的随机数不变. pendingintent传值经常获取到的值是第一次的值 ...
- Android消息通知(notification)和PendingIntent传值
通知栏的自定义布局:转:http://blog.csdn.net/vipzjyno1/article/details/25248021 拓展 实现自定义的通知栏效果: 这里要用到RemoteViews ...
- [问题解决]同时显示多个Notification时PendingIntent的Intent被覆盖?
情况是这样的,使用NotificationManager触发多个Notification: private Notification genreNotification(Context context ...
- Android控件之Notification
Android通知就是让设备在屏幕最顶上那栏里面显示图标,当滑下通知栏之后可以看到列表状的通知选项,有些是"通知"类型的,有些是"正在运行"类型的," ...
随机推荐
- 嵌入式linux性能详解_转
最近简单看了下<嵌入式Linux性能详解>一书,对系统内存分布测试.程序运行.动态库等都很很好的解析. 作者史子旺,loughsky@sina.com. 有时间希望仔细通读,并验证.
- Office Web App2013 在线查看PDF文件
经常会有客户问,在SharePoint中,如何在浏览器中查看与编辑文档,通常给出的解决方案是集成Office Web App. 而在实际应用过程中,客户通常会要求实现PDF文件在线查看,对于PDF文件 ...
- Android基础总结(一)项目结构,事件
Android项目的目录结构 Activity:应用被打开时显示的界面 src:项目代码 R.java:项目中所有资源文件的资源id Android.jar:Android的jar包,导入此包方可使用 ...
- thinkphp 命名规范
目录和文件命名 目录和文件名采用 小写+下划线,并且以小写字母开头: 类库.函数文件统一以.php为后缀: 类的文件名均以命名空间定义,并且命名空间的路径和类库文件所在路径一致(包括大小写): 类名和 ...
- python的卸载方式和运行yum报错:No module named yum
公司测试机环境不知道给我卸了什么包,导致yum运行报错状况: 系统版本:Red Hat Enterprise Linux Server release 6.2 (Santiago) 内核版本:2.6. ...
- 构造 - Codeforces Round #319 (Div. 1)C. Points on Plane
Points on Plane Problem's Link Mean: 在二维坐标中给定n个点,求一条哈密顿通路. analyse: 一开始忽略了“无需保证路径最短”这个条件,一直在套最短哈密顿通路 ...
- zabbix服务器搭建
zabbix服务器源码安装 参看官方文档 这里不做过多的翻译,我的系统是centos6.5,安装的时候是base安装,所以要装一些其他依赖包,除此之外,还有一些php插件: extension=bcm ...
- JSP 页面中用绝对路径显示图片
首先,图片和工程不在一个盘符下.图片也不能放到工程下. 在JSP 文件中 <img src="E:/图片/1.jpg"/> 这样是引不到图片的.因为,JSP页面在引 ...
- 目标检测YOLO算法-学习笔记
算法发展及对比: 17年底,mask-R CNN YOLO YOLO最大的优势就是快 原论文中流程,可以检测出20类物体. 红色网格-张量,在这样一个1×30的张量中保存的数据 横纵坐标中心点缩放到0 ...
- ssm异步上传图片
1.首先引入jersey jar包 2.在配置文件中,配置允许上传图片 3.修改增加商品页面 <%@ page language="java" import=" ...