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之处 ...
随机推荐
- springboot 项目添加jaeger调用链监控
1.添加maven依赖<dependency> <groupId>io.opentracing.contrib</groupId> <artifactId&g ...
- Hadoop(四)shell脚本定时采集日志数据到hdfs
#!/bin/bash #set java envexport JAVA_HOME=/wocloud/java/jdk1.7.0_45export JRE_HOME=${JAVA_HOME}/jree ...
- Spring Boot 2.0(三):使用 Docker 部署 Spring Boot
Docker 技术发展为微服务落地提供了更加便利的环境,使用 Docker 部署 Spring Boot 其实非常简单,这篇文章我们就来简单学习下. 首先构建一个简单的 Spring Boot 项目, ...
- MacDev.GetArchOfLibrary
1. static library How to check target architecture of a static library http://changhoward.blogspot.c ...
- 让delphi像C语言一样灵活
lazarus是免费的delphi 拥有和c语言一样的灵活性,见代码: procedure TForm1.FormCreate(Sender: TObject);var p:PIntegerArray ...
- [Robot Framework] 通过RemoteWhiteLibrary启动程序并登录初尝试
启动remote whitelibrary之后,在robot framework中配置好library,就可以调用whitelibrary的关键字了 启动APP White.LAUNCHAPP ...
- python -u
标准错误(std.err):直接打印到屏幕 标准输出(std.out):需要缓存后再输出到屏幕 sys.stdout.write("stdout1") sys.stderr.wri ...
- 教你避雷!网页设计中常见的17个UI设计错误集锦(附赠设计技巧)
以下内容由摹客团队翻译整理,仅供学习交流,摹客iDoc是支持智能标注和切图的产品协作设计神器. 精心设计的用户界面对网站意义重大.具备所有最新功能和响应式设计有助于提高网站的搜索引擎排名,从而增加受众 ...
- 更精确的判断对象类型js方法
function isArray(o) { return Object.prototype.toString.call(o) === '[object Array]'; } function isRe ...
- CXF wsdl2java (转载)
2011-03-28 14:27 9735人阅读 评论(2) 收藏 举报 servicewebserviceinterfacejavastringserver CXF wsdl2Java 一. 简介 ...