android 通知过滤,android – 多个通知处理

我无法搞清楚Intent,PendingIntent过滤器和标志的通知.

通知正在工作,并且正在按原样生成,但问题是只有最后创建的通知才能保留Bundle Data.

我希望所有通知都保留每个通知的Bundle Data,直到用户点击它们为止.

考虑一个应用程序片刻,当不同的用户向您发送消息时,会创建新通知,当您单击任何通知时,应用程序将启动并带您进入某些特定的活动.我想要相同的东西,但是当有多个通知时,最后一个通知会将Data保留在上一个通知中,而其中包含Bundle Data和Intent.

每次点击通知时,还有一个过滤器用于限制应用程序启动MainActivity的新实例.

每个通知的Notification_ID都不同.

public class AlarmSchedulingService extends IntentService {

private NotificationManager mNotificationManager;

public AlarmSchedulingService() {

super("SchedulingService");

}

protected void onHandleIntent(Intent intent) {

Bundle extras = intent.getExtras();

sendNotification(extras.getInt(KEY_EXTRAS_NOTIFICATION_ID));

}

public void sendNotification(int NOTIFICATION_ID) {

mNotificationManager = (NotificationManager) this

.getSystemService(Context.NOTIFICATION_SERVICE);

Intent intent = new Intent(this,MainActivity.class);

intent.putExtra(keyName,extraData);

intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);

PendingIntent contentIntent = PendingIntent.getActivity(this,intent,PendingIntent.FLAG_UPDATE_CURRENT);

// use the right class it should be called from the where alarms are set

NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(

this)

.setAutoCancel(true)

.setSmallIcon(R.drawable.ic_launcher)

.setContentTitle(titleString)

.setStyle(

new NotificationCompat.BigTextStyle()

.bigText(messageString))

.setDefaults(

Notification.DEFAULT_SOUND

| Notification.DEFAULT_LIGHTS)

.setContentText(messageString);

mBuilder.setContentIntent(contentIntent);

mNotificationManager.notify(NOTIFICATION_ID,mBuilder.build());

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值