android 多通知 参数问题, PendingIntent:有用的requestCode参数
来源:互联网 发布:李天生sql server2008 编辑:程序博客网 时间:2024/06/02 07:30
android 多通知 参数问题, PendingIntent:有用的requestCode参数
目录(?)[+]
转http://harvey8819.blog.163.com/blog/static/162365181201132691559986/
今天真算是吃尽了苦头,往Android的notifications里增加一条记录的时候,如果只需要一条通知无问题,但如果根据不同情况添加不同的通知,我们知道可通过方法notificationManager.notify(id,notification)的id参数指定不同的id就行了,但事实上通常会出现以下问题:我们一般会通过一个PendingIntent指定一个Intent,使点击notification后跳转到指定的视图,可是奇怪的是,当我添加了两条以上通知并通过Bundle传送了一些数据之后,后面传的Bundle中的数据会把前面的覆盖掉,也就是说无论添加了多少条通知,点击跳转过去的视图都变成一样的了。百思不得其解。
搜了大量资料后,才偶然发现是PendingIntent 的问题:
PendingIntent 需要通过以下方法取得:PendingIntent.getActivity (Context context, int requestCode, Intent intent, int flags),看sdk,对这个方法这样描述:
public static PendingIntent getActivity (Context context, int requestCode, Intent intent, int flags)
Retrieve a PendingIntent that will start a new activity, like calling Context.startActivity(Intent)
. Note that the activity will be started outside of the context of an existing activity, so you must use the Intent.FLAG_ACTIVITY_NEW_TASK
launch flag in the Intent.
Parameters
FLAG_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.Returns
- Returns an existing or new PendingIntent matching the given parameters. May return null only if
FLAG_NO_CREATE
has been supplied.
我们看到requestCode打了括号说明是currently not used,既然还没使用,我就像网上很多例子一样随便给一个0就算了。可实际上这个参数是有用的:当同时有多个通知的时候,可通过这个参数来互相区别,否则的话,就像我开始遇到的情况,后加进去的Intent会把前面的盖掉。弄清楚了这点,事情就好办了,我把PendingIntent.getActivity的requestCode参数设成了与noti
- android 多通知 参数问题, PendingIntent:有用的requestCode参数
- android 多通知 参数问题, PendingIntent:有用的requestCode参数
- android PendingIntent:有用的requestCode参数
- Android 通知栏 PendingIntent.getActivity(context, requestCode, intent, flags);参数详解
- android 通知覆盖以及PendingIntent参数问题
- 通知栏PendingIntent传递参数始终为null的问题
- 【Android 非常基础】多通知 PendingIntent.getActivity参数使用
- Android消息通知PendingIntent传递参数出问题
- PendingIntent 传递参数的问题
- PendingIntent 传递参数的问题
- PendingIntent传参数问题
- Android PendingIntent的getAcetivity()参数的困惑
- 推送通知栏 PendingIntent 参数解读
- android PendingIntent参数详细解析
- android PendingIntent参数详细解析
- PendingIntent requestCode
- --------------Android 4.2 通知通过PendingIntent启动Activity失败的问题
- 解决PendingIntent传递参数为空的问题
- Servlet学习笔记1
- 第十周项目一 程序填充1
- 2014-10-31Android学习------setContentView(View view)--------GIF动画实现
- c++排序算法——简单桶排序
- Linux权限处理常用的四个命令详解
- android 多通知 参数问题, PendingIntent:有用的requestCode参数
- 寻找最大数(三)
- 复用类-java编程思想-第七章
- 第十周项目一 了解getchar()的用法
- 第十周项目2--M$pszi$y是嘛意思?
- 详细理解端口号
- Huffman编码
- ios TabBat 中图标设计模糊的问题
- 执行力在ERP系统中发挥的作用