Android状态栏通知(notification)PendingIntent传值(解决传值总是获取第一次的值的问题)
来源:互联网 发布:spss调查量表数据录入 编辑:程序博客网 时间:2024/05/21 17:52
Pendingintent传值问题
pendingintent传值经常获取到的值是第一次的值或者null,这个跟第二个参数和最后一个参数选择有关系。
PendingIntent pendingIntent = PendingIntent.getActivity(this, id, intent, PendingIntent.FLAG_UPDATE_CURRENT);
注:如果所要启动的Activity是单例模式,其传值方法请看onNewIntent调用时机
总结一下pendingIntent的常用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值.
- Android状态栏通知(notification)和PendingIntent传值(解决传值总是获取第一次的值的问题)
- Android状态栏通知(notification)PendingIntent传值(解决传值总是获取第一次的值的问题)
- Android的状态栏通知(Notification)
- Android的状态栏通知(Notification)
- Android的状态栏通知(Notification)
- Android的状态栏通知(Notification)
- Android的状态栏通知(Notification)
- Android 的状态栏通知(Notification)
- Android自定义状态栏通知(Status Notification)的正确实现
- Android自定义状态栏通知(Status Notification)的正确实现
- Android自定义状态栏通知(Status Notification)的正确实现
- Android自定义状态栏通知(Status Notification)的正确实现
- Android自定义状态栏通知(Status Notification)的正确实现
- Android自定义状态栏通知(Status Notification)的正确实现
- Android自定义状态栏通知(Status Notification)的正确实现
- Android自定义状态栏通知(Status Notification)的正确实现
- Android自定义状态栏通知(Status Notification)的正确实现
- Android手机状态栏通知(Notification)的功能与用法
- MINGW ECLIPSE C++UNIT
- GTEST Value Parameterized
- 软件自动化测试框架的发展
- python时间戳转换时间量值
- php 跨域 form提交 2种方法
- Android状态栏通知(notification)PendingIntent传值(解决传值总是获取第一次的值的问题)
- CSDN的那些事
- 玩转Google单元测试框架gtest系列之三:事件机制
- Content Provider
- 调试BUG之打印输出,但是没输出
- 【徒手训练】来自美国特种部队的徒手三角肌训练法
- 关于IT实例教程
- 在windows平台上解决oracle.exe的cpu使用高的问题
- virtual box 4.3.4安装64位系统