Intent intent=new Intent(this, RingBellActivity.class);
LogInfo.d("alarmID="+alarmID);
intent.putExtra("AlarmID",alarmID);
intent.putExtra("fromNotificatin",true);
PendingIntent pi=PendingIntent.getActivity(this,0,intent,0);
Notification notification=new NotificationCompat.Builder(this,"alarm1")
.setSmallIcon(R.mipmap.ic_launcher_round)
.setLargeIcon(BitmapFactory.decodeResource(getResources(),R.mipmap.ic_launcher_round))
.setContentTitle(name)
.setContentText(time)
.setContentIntent(pi)//点击结束响铃并且跳到闹钟列表页面,且页面更新
.build();
notification.fullScreenIntent=pi;
notificationManager.notify(alarmID,notification);
在上述代码中,已经给intent.putExtra(“AlarmID”,alarmID);赋值了,但是在RingBellActivity启动时,获取到的还是以前的值。最后发现是构建PendingIntent时的flag值没有设置正确。
PendingIntent pi=PendingIntent.getActivity(this,0,intent,0);
应该改为
PendingIntent pi=PendingIntent.getActivity(this,0,intent,PendingIntent.FLAG_UPDATE_CURRENT);
把最后的参数设置为 PendingIntent.FLAG_UPDATE_CURRENT,才会刷新Intent的值
版权声明:本文为m0_37910557原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。