PendingIntent的Flags
PendingIntent是一个Intent的描述、包装,给予了这个PendingIntent 的组件在指定的事件发生或指定的时间到达时启动Activty、Service或者Broadcast。
根据是要启动Activity、Service还是Broadcast分别对应一个获取PendingIntent的方法
public static PendingIntent getActivity(Context context, int requestCode,
Intent intent, int flags)
public static
PendingIntent getBroadcast(Context context, int requestCode,
Intent intent, int flags)
;
public static PendingIntent getService(Context context, int requestCode,
Intent intent, int flags)
三个函数的参数都相同,其中最后一个参数flags在文档中是这样解析的:
flags: May beFLAG_ONE_SHOT,FLAG_NO_CREATE,FLAG_CANCEL_CURRENT, FLAG_UPDATE_CURRENT,
or any of the flags as supported by Intent.fillIn() to control which unspecified parts of the intent that can be supplied when the actual send happens.
目前为止只提供FLAG_ONE_SHOT, FLAG_NO_CREATE, FLAG_CANCEL_CURRENT,
FLAG_UPDATE_CURRENT这四个flag
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的区别在于能否新new一个Intent,FLAG_UPDATE_CURRENT能够新new一个Intent,而FLAG_CANCEL_CURRENT则不能,只能使用第一次的Intent。是否更新还取决于第二个参数,如果第二个
另外两flag就比较少用,利用FLAG_ONE_SHOT获取的PendingIntent只能使用一次,即使再次利用上面三个方法重新获取,再使用PendingIntent也将失败,利用FLAG_NO_CREAT获取的PendingIntent若描述的Intent不存在则返回NULL值.
注意当需要发送不同的pendingIntent 的时候 必须设置不同的
requestCode .否者将会出现可能多次发送的是同一个intent事件
PendingIntent的Flags的更多相关文章
- android: PendingIntent的使用
PendingIntent的Flags的类型: * Flags的类型: FLAG_ONE_SHOT:得到的pi只能使用一次,第二次使用该pi时报错 FLAG_NO_CREATE: 当pi不存在时,不创 ...
- android 多个notifycation向同一个Actiivity传递不同数据
如果你有这方面的需求,那你实践的时候可能会发现,多个Notifycation点击的时候会传递相同的数据. 通常情况下我们可能这样写. Notification notification = new N ...
- Notification
一:普通Notification 1.内容标题setContentTitle(...) 2.大图标setLargeIcon(Bitmap) 3.内容setContentText(...) 4.内容附加 ...
- Android开发中的问题及相应解决(持续更新)
最近博客写的少了,以后还得经常更新才行. ------------------------------------------------------------ 1.特定业务需求下try cath ...
- Android RemoteViews 11问11答
1.什么是RemoteView? 答:其实就是一种特殊的view结构,这种view 能够跨进程传输.并且这种remoteview 还提供了一些方法 可以跨进程更新界面.具体在android里面 一个是 ...
- Notification在不同版本SDK中的使用
今天总结了一下Notification的使用,发现这个控件在版本上有点扯淡.API11和API16两个分水岭,导致菜鸟在学习的时候比较吃力,受影响的外界因素是多样的,其中比较重要的就是你测试的andr ...
- Service详解
/** * 后台执行的定时任务 */ public class LongRunningService extends Service { @Override public IBinder onBind ...
- Android学习笔记_30_常用控件使用
一.状态栏通知(Notification): 如果需要查看消息,可以拖动状态栏到屏幕下方即可查看消息.发送消息的代码如下: public void sendNotice(View v){ int ic ...
- Android更新带进度条的通知栏
在网上查询了下.Android版本号更新通知栏带进度条,醉了,基本都是复制过来.有的代码不全,连源代码下载都没有.有下载也须要积分,还不能用,真黑心啊!!之前自己也写过自己定义通知栏Notificat ...
随机推荐
- hdu2044java
一只小蜜蜂... Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submi ...
- linux根下目录详解及分区建议
/ 根目录 分区大小一定要充足,一般不小于5GB/bin,/usr/bin 普通用户使用命令 建议和/放一起/sbin,/usr/sbin 管理员使用命令/bin,/sbin 操作系统自身 ...
- VOL.1 利用vmware ThinApp 制作非XP下可以运行的IE6 【无插件版】(windows vista/7/8 x86/x64 )
作为一名前端开发工程师,不免要考虑IE6的兼容性,但是大部分挑剔的同行们估计都不会用XP,所以基本上IE6的兼容性测试,都是使用IE Tester或者虚拟机. IE Tester的话,很多地方模拟的还 ...
- jquery.qrcode和jqprint的联合使用,实现html生成二维码并打印(中文也ok)
在公司的生产现场中,常常会在一些部品或设备上贴上二维码,用于扫描录入数据,免去手动输入的麻烦. 以前曾经做过winform的程序,生成二维码,并打印出来,使用的是zxing的类库, 但是如果二维码是附 ...
- Mysql内存表的用处
文章出自:http://blog.csdn.net/hitzhang/article/details/5994639 个人最欣赏mysql的地方就是他存储引擎的多样性和可扩展性,这样mysql也能拥有 ...
- DBA词典:数据库设计常用词汇中英文对照表
1. Access method(访问方法):此步骤包括从文件中存储和检索记录. 2. Alias(别名):某属性的另一个名字.在SQL中,可以用别名替换表名. 3. Alternate keys(备 ...
- oracle数据库的导出与导入
导出:exp devtest10/dev10@172.16.7.39:1521/WSRZ file=d:\WSRZ.dmp log=d:\WSRZ.log full=y 导入:imp testdb/t ...
- UITableView中容易忽略的知识点
1.取消余下的分割线 tableView.tableFooterView = UIView() 2.分割线顶格 override func viewDidLayoutSubviews() { self ...
- CSS 组合选择符
CSS 组合选择符 组合选择符说明了两个选择器直接的关系. CSS组合选择符包括各种简单选择符的组合方式. 在 CSS3 中包含了四种组合方式: 后代选取器(以空格分隔) 子元素选择器(以大于号分隔) ...
- java学习之反射机制
java语言区别于C,C++等准静态语言的最大特点就是java的反射机制.静态语言的最直接定义就是不能在运行时改变程序结构或变量的类型.按照这样的定义,python,ruby是动态语言,C,C++,J ...