Android:PendingIntent的FLAG_CANCEL_CURRENT和FLAG_UPDATE_CURRENT
来源:互联网 发布:网络监管员是做什么的 编辑:程序博客网 时间:2024/04/30 13:02
当我们自己使用Notification在通知栏提示消息时,我们通过点击下拉的消息,来打开app指定的页面,如果需要传递更多信息时,可以通过PendingIntent。
在使用中,碰到了一些问题,主要是参数FLAG_CANCEL_CURRENT和FLAG_UPDATE_CURRENT,总结如下:
PendingIntent有一个getActivity方法,第一个参数是上下文,没啥好说的,第二个参数 requestCode,这个后面说,第三个参数是 Intent,用来存储信息,第四个参数是对参数的操作标识,常用的就是FLAG_CANCEL_CURRENT和FLAG_UPDATE_CURRENT。
当使用FLAG_UPDATE_CURRENT时:
PendingIntent.getActivity(context, 0, notificationIntent,PendingIntent.FLAG_CANCEL_CURRENT时);
FLAG_UPDATE_CURRENT会更新之前PendingIntent的消息,比如,你推送了消息1,并在其中的Intent中putExtra了一个值“ABC”,在未点击该消息前,继续推送第二条消息,并在其中的Intent中putExtra了一个值“CBA”,好了,这时候,如果你单击消息1或者消息2,你会发现,他俩个的Intent中读取过来的信息都是“CBA”,就是说,第二个替换了第一个的内容
当使用FLAG_CANCEL_CURRENT时:
依然是上面的操作步骤,这时候会发现,点击消息1时,没反应,第二条可以点击。
导致上面两个问题的原因就在于第二个参数requestCode,当requestCode值一样时,后面的就会对之前的消息起作用,所以为了避免影响之前的消息,requestCode每次要设置不同的内容。
- Android:PendingIntent的FLAG_CANCEL_CURRENT和FLAG_UPDATE_CURRENT
- Android:PendingIntent的FLAG_CANCEL_CURRENT和FLAG_UPDATE_CURRENT
- Android:PendingIntent的FLAG_CANCEL_CURRENT和FLAG_UPDATE_CURRENT
- PendingIntent的FLAG_CANCEL_CURRENT和FLAG_UPDATE_CURRENT
- android FLAG_CANCEL_CURRENT FLAG_UPDATE_CURRENT
- Android PendingIntent和Intent的区别
- Android Intent和PendingIntent的区别
- Android-Intent和PendingIntent的关系
- [整理]Android Intent和PendingIntent的区别
- android Intent和PendingIntent的区别
- android中的Intent和PendingIntent的区别
- Android:Intent和PendingIntent的区别
- Android Intent和PendingIntent的区别
- Android中Intent和PendingIntent的区别
- 【Android】pendingIntent和Intent
- PendingIntent android.app.PendingIntent.getActivity的使用
- Android PendingIntent的使用
- Android PendingIntent的理解
- Cocos2d-x里面的HelloCpp项目不显示文字(或中文出现乱码)--解决方案
- Unix/Linux下的/etc目录
- ARM QT移植详细步骤教程
- SQL面试常见问题处理:查询和删除重复记录
- Nand ECC校验和纠错原理及2.6.27内核ECC代码分析
- Android:PendingIntent的FLAG_CANCEL_CURRENT和FLAG_UPDATE_CURRENT
- 自己写一个MVC框架
- 1_顺序表基本操作
- phonegap push-消息推送实现
- JAVA导入
- popupWindow显示位置的探究以及canvas的起始位置
- 在lua中 获取1到n的随机数列
- Android Broadcast 和 BroadcastReceiver的权限限制
- android viewpager自适应