[英]How maintain GCM push message in Android, its replaced by new one
我的Android应用程序收到带有一些文本消息的推送通知。如果我点击某个推送,它将使用最新的推送消息(意图消息)将我重定向到所需的活动,但我想通过相应的推送消息显示所需的活动。 例如,如果我收到10个推送通知,然后点按第3个通知,则我的代码会将我重定向到具有第10个推送通知的消息的指定活动,但我想显示第3个意图推送通知的消息。
我知道PendingIntent.FLAG_UPDATE_CURRENT替换了意图消息,如何用相应的消息而不是最后一条消息重定向?
我尝试了以下方法:
Intent intent = new Intent(this, TestActivity2.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_CLEAR_TASK);
intent.putExtra("uid", uid);
PendingIntent resultPendingIntent = PendingIntent.getActivity(this, 0,
intent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
getApplicationContext());
Notification notification = mBuilder
.setSmallIcon(R.drawable.ic_launcher)
.setTicker(textMsg)
.setWhen(0)
.setAutoCancel(true)
.setContentTitle(textMsg)
.setStyle(
new NotificationCompat.BigTextStyle().bigText(textMsg))
.setContentIntent(resultPendingIntent).setContentText(textMsg)
.build();
NotificationManager notificationManager = (NotificationManager) getApplicationContext()
.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify((int) System.currentTimeMillis(),
notification);
请改用FLAG_ONE_SHOT
然后将getActivity
的第二个参数更改为0。 此答案将使之很清楚。
您应该更改“不同消息”的pendingIntend的内容。 这是PendingIntent文档的摘录。 “ PendingIntent本身只是对系统维护的令牌的引用,该令牌描述了用于检索它的原始数据。这意味着,即使其拥有的应用程序的进程被杀死,PendingIntent本身也可以从已给定的其他进程中继续使用如果创建应用程序以后重新检索相同类型的PendingIntent(相同的操作,相同的Intent操作,数据,类别和组件以及相同的标志),则它将收到代表相同令牌的PendingIntent(如果该令牌仍然有效),因此可以调用cancel()将其删除。”
用简单的话说...尝试为每个pendingIntent传递不同的id(类似currentEpochTime)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.