主要出在PendingIntent.getActivity();的第二个参数,API文档里虽然说是未被使用的参数(给出的例子也直接写0的),实际上是通过该参数来区别不同的Intent的,如果id相同,就会覆盖掉之前的Intent了。所以总是获取到最后一个Intent。

只要每个不同的Intent对应传递一个独立的ID就可以了,以上函数修改如下(增加ID参数):

package com.gf.messaging.implemention.handler;

import org.json.JSONObject;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast; import com.gf.messaging.MessagePushService;
import com.gf.messaging.MessagePushServiceConfig; public class NotificationHandler {
private static int NOTIFICATION_ID = 0x30001;//通知栏消息id
private MessagePushService mService;
private MessagePushServiceConfig mConfig; public NotificationHandler(MessagePushService service, MessagePushServiceConfig config){
mService = service;
mConfig = config;
} public void handleNotification(JSONObject jsonPayload) {
PushNotiInfo pni = ExplanationPushNoti.getPushNoti(jsonPayload);
String payload = jsonPayload.optJSONObject("data").optString("message");
NotificationManager notificationManager = (NotificationManager) mService.getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = new Notification(
mConfig.iconId, payload, System
.currentTimeMillis());
notification.flags |= Notification.FLAG_AUTO_CANCEL; Intent launchIntent = new Intent("com.gf.messaging.QuotationWindow");//mConfig.intentAction
launchIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_NEW_TASK);
launchIntent.putExtra("stock_code",
pni.code);
launchIntent.putExtra("stock_name",
pni.stockName);
String temp = pni.market;
if(temp.equals("sz"))
launchIntent.putExtra("stock_market",
1);
else
launchIntent.putExtra("stock_market",
0); PendingIntent pendingIntent = PendingIntent.getActivity(mService.getApplicationContext(),
NOTIFICATION_ID, launchIntent, PendingIntent.FLAG_UPDATE_CURRENT);
notification.contentIntent = pendingIntent;
notification.setLatestEventInfo(
mService.getApplicationContext(),
mConfig.notificationTitle, payload, pendingIntent); notificationManager.notify(NOTIFICATION_ID++,
notification); if(NOTIFICATION_ID == 10) notificationManager.cancel(NOTIFICATION_ID - 10);// 取消之前的通知消息; }
}

更多的移动互联网的发展趋势app开发移动互联网应用相关的资料请到互联网的一点事www.yidin.net 留言

android QQ群:222392467

资料:

http://www.yidin.net/?p=8280

http://www.yidin.net/?p=9725

http://my.oschina.net/yidinshi/blog/133729

同时显示多个 Notification的更多相关文章

  1. 轻松让HTML5可以显示桌面通知Notification非常实用

    使用Notification的流程 1.检查浏览器是否支持Notification2.检查浏览器的通知权限3.如果权限不够则申请获取权限4.创建消息通知5.展示消息通知 Notification AP ...

  2. [问题解决]同时显示多个Notification时PendingIntent的Intent被覆盖?

    情况是这样的,使用NotificationManager触发多个Notification: private Notification genreNotification(Context context ...

  3. Notification状态栏显示信息

    Notification即通知,用于在通知栏显示提示信息. 在API Level > 11,Notification类中的一些方法被Android声明deprecated(弃用),而在API L ...

  4. Android中使用Notification实现宽视图通知栏(Notification示例二)

    Notification是在你的应用常规界面之外展示的消息.当app让系统发送一个消息的时候,消息首先以图表的形式显示在通知栏.要查看消息的详情需要进入通知抽屉(notificationdrawer) ...

  5. 安卓Notification的setLatestEventInfo is undefined出错不存在的解决

    用最新版的SDK,在做状态栏通知时,使用了Notification的setLatestEventInfo(),结果提示: The method setLatestEventInfo(Context, ...

  6. android: Android Notification

    Notification即通知,用于在通知栏显示提示信息. 在较新的版本中(API level  > 11),Notification类中的一些方法被Android声明deprecated(弃用 ...

  7. 添加常驻Notification

    private static final int NOTIFICATION_ID=250; //用来标示notification,通过notificatinomanager来发布同样标示的notifi ...

  8. 通知(Toast+Notification)

    Toast简要说明:(前面已经用过好多次了) Toast是一种非持久的(在屏幕上面留一会儿就消失了),提供给用户简洁提示信息的视图. 它不阻断用户的操作,一般用于显示一些不重要的信息.(比方说设置音量 ...

  9. Android 状态栏通知Notification、NotificationManager简介

    Notification(通知)一般用在电话,短信,邮件,闹钟铃声,在手机的状态栏上就会出现一个小图标,提示用户处理这个通知,这时手从上方滑动状态栏就可以展开并处理这个通知: 在Android系统中, ...

随机推荐

  1. CF437D(The Child and Zoo)最小生成树

    题目: D. The Child and Zoo time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  2. jsp获得本地及serverIP的方法

    InetAddress addr = InetAddress.getLocalHost(); String ip = addr.getHostAddress().toString();//获得本机IP ...

  3. open sql 更新数据

    insert语句: 1.插入单行数据有两种方法:wa是一个工作区 insert into dbtab values wa. insert into dbtab from wa. 该语句也可以将数据行插 ...

  4. 手动配置S2SH三大框架报错(一)

    十二月 08, 2013 9:24:51 下午 org.apache.catalina.core.AprLifecycleListener init 严重: An incompatible versi ...

  5. 居然还有FindFirstChangeNotification函数

    http://download.csdn.net/download/sololie/5966243

  6. opencv 边缘羽化,边缘过渡

    原地址:http://blog.csdn.net/sogarme/article/details/12942971 当把前景和背景分开时,黑色代表背景,白色代表前景,如下图1—记作img1 为了平滑过 ...

  7. 【编程之美】java二进制实现重建

    package com.cn.binarytree.utils; /** * @author 刘利娟 liulijuan132@gmail.com * @version 创建时间:2014年7月20日 ...

  8. Android开发周报:反编译对抗研究、动手制作智能镜子

    新闻 <Android Wear落地中国 谷歌增强安卓生态控制力> :9月8日,由摩托罗拉推出的智能手表Moto 360二代作为国内发售的第一款搭载官方Android Wear的设备,正式 ...

  9. projecteuler----&gt;problem=9----Special Pythagorean triplet

    title: A Pythagorean triplet is a set of three natural numbers, a b c, for which, a2 + b2 = c2 For e ...

  10. 浏览器url传参中文时得到null的解决方法

    在写一个中文参数需求的时候遇到了以下问题,经过半天的测试和各种编码,以及网上一些有用没用的资料尝试终于解决    比如下面的url地址:http://travel.widget.baike.com:8 ...