我是靠谱客的博主 闪闪路人,这篇文章主要介绍解决Notification PendingIntent意图打开Activity数据没有更新的问题,现在分享给大家,希望可以做个参考。

在使用Notification通知时,如果没有设置PendingIntent.FLAG_UPDATE_CURRENT就会出现在通知栏点击第二条通知时还是第一条的通知的数据,以下解释:

8. PendingIntent中定义了几个FLAG。

(1) android.app.PendingIntent.FLAG_UPDATE_CURRENT

如果PendingIntent已经存在,保留它并且只替换它的extra数据。

int android.app.PendingIntent.FLAG_UPDATE_CURRENT = 134217728 [0x8000000] 
Flag for use with getActivity, getBroadcast, and getService: if the described PendingIntent already exists, then keep it but its replace its extra data with what is in this new Intent. This can be used if you are creating intents where only the extras change, and don't care that any entities that received your previous PendingIntent will be able to launch it with your new extras even if they are not explicitly given to it.


代码:

 Context context = getApplicationContext();
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.jpush_notification_icon, "南方有道", System.currentTimeMillis());
notification.flags = Notification.FLAG_AUTO_CANCEL;
//点击后自动消失
Intent intent = new Intent(this,TestActivity.class);
intent.putExtra("message", msg);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
notification.setLatestEventInfo(context, "标题", msg, pendingIntent);
notificationManager.notify(0, notification);



最后

以上就是闪闪路人最近收集整理的关于解决Notification PendingIntent意图打开Activity数据没有更新的问题的全部内容,更多相关解决Notification内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(46)

评论列表共有 0 条评论

立即
投稿
返回
顶部