Notification中PendingIntent.Flag的应用
来源:互联网 发布:python csv文件 求和 编辑:程序博客网 时间:2024/05/16 13:41
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 be FLAG_ONE_SHOT,LAG_NO_CREATE,LAG_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_ONE_SHOT获取的PendingIntent只能使用一次,即使再次利用上面三个方法重新获取,再使用PendingIntent也将失败。
FLAG_NO_CREATE:if the described PendingIntent does not already exist, then simply return null instead of creating it.
利用FLAG_NO_CREAT获取的PendingIntent,若描述的Intent不存在则返回NULL值.
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.
如果描述的PendingIntent已经存在,则在产生新的Intent之前会先取消掉当前的。你可用使用它去检索新的Intent,如果你只是想改变Intent中的额外数据的话。通过取消先前的Intent,可用确保只有最新的实体可用启动它。如果这一保证不是问题,考虑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.
最经常使用的是FLAG_UPDATE_CURRENT,因为描述的Intent有 更新的时候需要用到这个flag去更新你的描述,否则组件在下次事件发生或时间到达的时候extras永远是第一次Intent的extras。
上面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。
此外还需要注意参数:
int requestCode : Private request code for the sender (currently not used).
PendingIntent contentIntent = PendingIntent.getActivity(context,
num, intent, PendingIntent.FLAG_UPDATE_CURRENT);
对于FLAG_UPDATE_CURRENT,如果上面的requestCode 为常量,则对于先后出现的若干Notification,则所有对应的Intent里面的extra被更新为最新的,就是全部同一为最后一次的。
相反,如果num每次不一样,则里面的Inent的数据没被更新。
对于FLAG_CANCEL_CURRENT,则只响应最前面的第一条Notifiacation,后面所有的不响应....
使用请参考:http://txlong-onz.iteye.com/blog/1142737
根据是要启动Activity、Service还是Broadcast分别对应一个获取PendingIntent的方法
public static PendingIntent getActivity(Context context, int requestCode,
public static PendingIntent getBroadcast(Context context, int requestCode
public static PendingIntent getService(Context context, int requestCode,
三个函数的参数都相同,其中最后一个参数flags在文档中是这样解析的:
flags:
目前为止只提供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_ONE_SHOT获取的PendingIntent只能使用一次,即使再次利用上面三个方法重新获取,再使用PendingIntent也将失败。
FLAG_NO_CREATE:if the described PendingIntent does not already exist, then simply return null instead of creating it.
利用FLAG_NO_CREAT获取的PendingIntent,若描述的Intent不存在则返回NULL值.
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.
如果描述的PendingIntent已经存在,则在产生新的Intent之前会先取消掉当前的。你可用使用它去检索新的Intent,如果你只是想改变Intent中的额外数据的话。通过取消先前的Intent,可用确保只有最新的实体可用启动它。如果这一保证不是问题,考虑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.
最经常使用的是FLAG_UPDATE_CURRENT,因为描述的Intent有 更新的时候需要用到这个flag去更新你的描述,否则组件在下次事件发生或时间到达的时候extras永远是第一次Intent的extras。
上面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。
此外还需要注意参数:
int requestCode : Private request code for the sender (currently not used).
PendingIntent contentIntent = PendingIntent.getActivity(context,
num, intent, PendingIntent.FLAG_UPDATE_CURRENT);
对于FLAG_UPDATE_CURRENT,如果上面的requestCode 为常量,则对于先后出现的若干Notification,则所有对应的Intent里面的extra被更新为最新的,就是全部同一为最后一次的。
相反,如果num每次不一样,则里面的Inent的数据没被更新。
对于FLAG_CANCEL_CURRENT,则只响应最前面的第一条Notifiacation,后面所有的不响应....
使用请参考:http://txlong-onz.iteye.com/blog/1142737
0 0
- Notification中PendingIntent.Flag的应用
- Android Notification中PendingIntent.Flag的应用
- Notification中PendingIntent的陷阱
- PendingIntent的flag
- 如何设置 Notification 中PendingIntent 的 Intent
- 如何设置 Notification 中PendingIntent 的 Intent
- 如何设置 Notification 中PendingIntent 的 Intent
- Notification(二)——PendingIntent的flag导致数据相同的问题
- Android PendingIntent的Flag设置
- Android的Notification应用详解和PendingIntent的初步剖解
- Android的Notification应用详解和PendingIntent的初步剖解
- Notification FLAG 的介绍
- Notification 的 Flag 设置
- 在notification中设置PendingIntent
- Notification 中PendingIntent 只打开最后一个Intent的问题
- Android 如何设置 Notification 中PendingIntent 的 Intent
- 关于onNewIntent的使用&PendingIntent flag赋值
- Notification PendingIntent
- Post-rock
- 基于栈的后缀表达法
- 在centos 6.2,python2.7 下安装QT 4.8.3,pyqt 4.9.5 详细步骤
- GMM:高斯混合模型的数学推导笔记(下)
- Android之自动化压力测试工具:Monkey的使用
- Notification中PendingIntent.Flag的应用
- 教你App如何上架应用宝----腾讯开放开发平台
- mysql中左连接,右连接,内连接查询,以及与where之间关系
- 从单调栈到计算1的矩阵
- 深入解析Android关机
- 网页常用js
- 入门Android开发--第一行代码--笔记系列(九)
- 如何获取到文件的创建时间,修改时间等参数
- 数据结构之二叉树的先序、中序、后续的求法