android PendingIntent 使用通知传递多个参数,及不覆盖的问题
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 使用通知传递多个参数,及不覆盖的问题的更多相关文章
- Android Handler之Message传递参数
最近发现Message,发送消息可以传递参数,这个思路很好,所以写了一个例子,点击屏幕,给Activity发送一个消息,传递两个参数,并把这个activity销毁掉! 程序打开界面: 点击屏幕,销毁a ...
- PendingIntent传递数据注意参数RequestCode和Flag
数据发送方: public static void notify(Context context, TxrjMessage msg) { NotificationManager notifiM ...
- Android中的通知—Notification 自定义通知
Android中Notification通知的实现步骤: 1.获取NotificationManager对象NotificationManager的三个公共方法:①cancel(int id) 取消以 ...
- Android开发——Notification通知的使用及NotificationCopat.Builder常用设置API
想要看全部设置的请看这一篇 [转]NotificationCopat.Builder全部设置 常用设置: 设置属性 说明 setAutoCancel(boolean autocancel) 设置点击信 ...
- 【Android】状态栏通知Notification、NotificationManager详解(转)
在Android系统中,发一个状态栏通知还是很方便的.下面我们就来看一下,怎么发送状态栏通知,状态栏通知又有哪些参数可以设置? 首先,发送一个状态栏通知必须用到两个类: NotificationMa ...
- Android Fragment间对象传递
由于Activity相对较为笨重,因而在日常的开发中很多时候会用到Fragment.然而Activity之间是通过Intent进行数据的传递,那Fragment是通过什么来进行传递的呢?Fragmen ...
- android Activity之间数据传递 Parcelable和Serializable接口的使用
Activity之间传数据时,为了避免麻烦,往往会将一些值封装成对象,然后将整个对象传递过去.传对象的时候有两种情况,一种是实现Parcelable接口,一种是实现Serializable接口.0.解 ...
- Appium Server 传递的基本参数
Appium Server 传递的基本参数 官方列表 Appium server capabilities Capability Description Values automationName ...
- wemall app商城源码Android之支付宝通知处理类
wemall-mobile是基于WeMall的Android app商城,只需要在原商城目录下上传接口文件即可完成服务端的配置,客户端可定制修改.本文分享wemall app商城源码Android之处 ...
随机推荐
- opencv 双边模糊,膨胀腐蚀 开 闭操作
#include <opencv2/opencv.hpp> #include <iostream> using namespace cv; int main(int argc, ...
- tensorflow.reshap(tensor,shape,name)的使用说明
tensorflow as tf tf.reshape(tensor, shape, name=None) reshape作用是将tensor变换为指定shape的形式. 其中shape为一个列表形式 ...
- openssl_error_string()
其实已经成功了,openssl_error_string()一样会输出错误信息,忽略就好
- 判断\r\n结束标准
ucPrev==0x0D&&ucCur==0x0A \r\n uint8_t ucPrev =0,ucCur = 0; uint32_t recvlen = 0; for (; uiL ...
- Netty 源码 ChannelHandler(三)概述
Netty 源码 ChannelHandler(三)概述 Netty 系列目录(https://www.cnblogs.com/binarylei/p/10117436.html) 一.Channel ...
- tomcat探索
双击apache-tomcat-7.0.64.exe,一路默认点. 静态页路径 C:\Program Files\Apache Software Foundation\Tomcat 7.0\webap ...
- python上下文管理协议
所谓上下文管理协议,就是咱们打开文件时常用的一种方法:with __enter__(self):当with开始运行的时候触发此方法的运行 __exit__(self, exc_type, exc_va ...
- jvm运行机制和volatile关键字详解
参考https://www.cnblogs.com/dolphin0520/p/3920373.html JVM启动流程 1.java虚拟机启动的命令是通过java +xxx(类名,这个类中要有mai ...
- service层代码相互调用, 导致spring循环依赖,设计上的优化
管理员创建用户需要发送激活邮件, 而发送激活邮件的时候需要判断发件人是不是合法的用户, 因此设计到一个循环依赖的问题 //UserService @Service class UserService{ ...
- 添加/删除-HTML DOM 常用对象 -BOM-打开和关闭窗口- history-location
1. 添加/删除 3步: 1. 添加一个空元素 var a=document.createElement("a"); <a></a> 2. 定义元素的关键属 ...