Android:PendingIntent的FLAG_CANCEL_CURRENT和FLAG_UPDATE_CURRENT
来源:互联网 发布:超市app送货上门软件 编辑:程序博客网 时间:2024/05/18 03:21
当我们自己使用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的理解
- HtmlParser整体框架
- Mac OS怎么查看系统隐藏文件
- 设计模式 笔记 中介者模式 Mediator
- 多接口使用同一套接词
- linux 系统调用
- Android:PendingIntent的FLAG_CANCEL_CURRENT和FLAG_UPDATE_CURRENT
- 百度副院长余凯在无锡CCF中的讲座心得
- apache开启.htaccess及.htaccess的使用方法
- android学习 -- ListView和数据库操作
- 1.solr5官方文档中文:快速入门
- 数据结构之顺序表
- 排序算法——希尔排序
- Eric Meyer css reset
- HTMLParser使用