Intent updateIntent = new Intent(GetNoticeService.this,
DetailGonggaoActivity.class); updateIntent.putExtra("type", "weidu"); updateIntent.putExtra("title",
(String) json.get("title"));
updateIntent.putExtra("id", json.get("noticeid")
.toString()); //加上这句就不会出现同一个activity出现多次的情况了
updateIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); //下面有对个参数,是设置的关键
PendingIntent updatePendingIntent = PendingIntent.getActivity(
GetNoticeService.this, i, updateIntent,PendingIntent.FLAG_UPDATE_CURRENT);
Notification updateNotification = new Notification();
// 设置通知栏显示内容
updateNotification.icon = R.drawable.logo;
updateNotification.flags |= updateNotification.FLAG_AUTO_CANCEL;
updateNotification.tickerText = "外勤精灵发来新的公告通知";
updateNotification.defaults = Notification.DEFAULT_SOUND;// 铃声提醒
updateNotification.setLatestEventInfo(
GetNoticeService.this,
"外勤精灵发来新的公告通知", (String) json.get("title"),
updatePendingIntent);
updateNotificationManager.notify(i, updateNotification);

  

//加上这句就不会出现同一个activity出现多次的情况了,不解释
updateIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
updateNotificationManager.notify(i, updateNotification);这句传递的i标记了updateNotification的位置和id相同的时候就覆盖原来的updateNotification,所以要传递不同的id,使不同的updateNotification不覆盖。
PendingIntent updatePendingIntent = PendingIntent.getActivity(
GetNoticeService.this, i, updateIntent,PendingIntent.FLAG_UPDATE_CURRENT);
Notification updateNotification = new Notification();
flags有四个取值:
int FLAG_CANCEL_CURRENT:如果该PendingIntent已经存在,则在生成新的之前取消当前的。
int FLAG_NO_CREATE:如果该PendingIntent不存在,直接返回null而不是创建一个PendingIntent.
int FLAG_ONE_SHOT:该PendingIntent只能用一次,在send()方法执行后,自动取消。
int FLAG_UPDATE_CURRENT:如果该PendingIntent已经存在,则用新传入的Intent更新当前的数据。

我们需要把最后一个参数改为PendingIntent.FLAG_UPDATE_CURRENT,这样在启动的Activity里就可以用接收Intent传送数据的方法正常接收。

前面的id作用一样

												

android PendingIntent 使用通知传递多个参数,及不覆盖的问题的更多相关文章

  1. Android Handler之Message传递参数

    最近发现Message,发送消息可以传递参数,这个思路很好,所以写了一个例子,点击屏幕,给Activity发送一个消息,传递两个参数,并把这个activity销毁掉! 程序打开界面: 点击屏幕,销毁a ...

  2. PendingIntent传递数据注意参数RequestCode和Flag

    数据发送方: public static void notify(Context context, TxrjMessage msg) {     NotificationManager notifiM ...

  3. Android中的通知—Notification 自定义通知

    Android中Notification通知的实现步骤: 1.获取NotificationManager对象NotificationManager的三个公共方法:①cancel(int id) 取消以 ...

  4. Android开发——Notification通知的使用及NotificationCopat.Builder常用设置API

    想要看全部设置的请看这一篇 [转]NotificationCopat.Builder全部设置 常用设置: 设置属性 说明 setAutoCancel(boolean autocancel) 设置点击信 ...

  5. 【Android】状态栏通知Notification、NotificationManager详解(转)

    在Android系统中,发一个状态栏通知还是很方便的.下面我们就来看一下,怎么发送状态栏通知,状态栏通知又有哪些参数可以设置? 首先,发送一个状态栏通知必须用到两个类:  NotificationMa ...

  6. Android Fragment间对象传递

    由于Activity相对较为笨重,因而在日常的开发中很多时候会用到Fragment.然而Activity之间是通过Intent进行数据的传递,那Fragment是通过什么来进行传递的呢?Fragmen ...

  7. android Activity之间数据传递 Parcelable和Serializable接口的使用

    Activity之间传数据时,为了避免麻烦,往往会将一些值封装成对象,然后将整个对象传递过去.传对象的时候有两种情况,一种是实现Parcelable接口,一种是实现Serializable接口.0.解 ...

  8. Appium Server 传递的基本参数

    Appium Server  传递的基本参数 官方列表 Appium server capabilities Capability Description Values automationName ...

  9. wemall app商城源码Android之支付宝通知处理类

    wemall-mobile是基于WeMall的Android app商城,只需要在原商城目录下上传接口文件即可完成服务端的配置,客户端可定制修改.本文分享wemall app商城源码Android之处 ...

随机推荐

  1. vs的【warning C4996:'fopen': This function or variable may be unsafe】解决方案

    编译警告:warning C4996 与 Security Enhancements in the CRT 将过去的工程用VS2005打开的时候.你有可能会遇到一大堆的警告:warning C4996 ...

  2. 2D情况下,复数的意义代表旋转

    4 x i x i = - 4 就是"4"在数轴上旋转了180度. 那么4 x i = 4i 就旋转了90度. 复数的意义就表示旋转 乘以-1,表示x正半轴的数,围绕原点,逆时针偏 ...

  3. android--Activity有返回值的跳转

    AndroidManifest.xml <?xml version="1.0" encoding="utf-8"?> <manifest xm ...

  4. hdu 1010(DFS) 骨头的诱惑

    http://acm.hdu.edu.cn/showproblem.php?pid=1010 题目大意从S出发,问能否在时间t的时候到达终点D,X为障碍 需要注意的是要恰好在t时刻到达,而不是在t时间 ...

  5. dpdk中文文档

    Linux平台上DPDK入门指南 1. 简介 1.1. 文档地图 2. 系统要求 2.1. X86 上预先设置 BIOS 2.2. 编译DPDK 2.3. 运行DPDK应用程序 3. 使用源码编译DP ...

  6. Windows下的PHP 5.3.x安装 Zend Guard Loader

    PHP5.3之后不再使用Zend Optimizer而是由Zend Guard Loader替换,而Zend Guard Loader安装比前者方便了很多,只有一个dll: 址:http://down ...

  7. MySQL Workbench常用快捷键

    执行当前SQL语句(即鼠标所在的SQL语句,以 ; 结尾) Ctrl + Enter 执行选中的SQL语句(或执行所有SQL语句) Ctrl + Shift + Enter

  8. Netty 源码 ChannelHandler(四)编解码技术

    Netty 源码 ChannelHandler(四)编解码技术 Netty 系列目录(https://www.cnblogs.com/binarylei/p/10117436.html) 一.拆包与粘 ...

  9. AWVS基本用法

    https://www.bugbank.cn/q/article/5983de41cbb936102d397781.html

  10. 通过 Spring Security配置 解决X-Frame-Options deny 造成的页面空白 iframe调用问题

    spring Security下,X-Frame-Options默认为DENY,非Spring Security环境下,X-Frame-Options的默认大多也是DENY,这种情况下,浏览器拒绝当前 ...