码迷,mamicode.com
首页 > 移动开发 > 详细

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

时间:2014-09-16 12:28:20      阅读:296      评论:0      收藏:0      [点我收藏+]

标签:android   blog   io   os   使用   java   ar   数据   div   

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   blog   io   os   使用   java   ar   数据   div   

原文地址:http://www.cnblogs.com/liaolandemengxiang/p/3974574.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!