如果我有一个被用户关闭的 Activity (用户按下主页,所以应用程序仍在应用程序堆栈中) 然后他收到通知,当他按下它时,我开始了一项 Activity 现在同一个 Activity 被打开了两次。 我怎样才能防止这种情况发生?
我的代码:
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
new Intent(this, MainActivity.class), PendingIntent.FLAG_UPDATE_CURRENT);
NotificationManager mNotificationManager = (NotificationManager)
this.getSystemService(Context.NOTIFICATION_SERVICE);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.logo)
.setContentTitle("Title")
.setStyle(new NotificationCompat.BigTextStyle().bigText(msg))
.setAutoCancel(true)
.setLights(GCMSIntentService.PURPLE, 500, 500)
.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
.setContentText(msg);
mBuilder.setContentIntent(contentIntent);
mNotificationManager.notify(1, mBuilder.build());
最佳答案
android:launchMode="singleTask"
在 list 中或者, 将其用作您的 Intent 的标志。
关于android - 按下通知会打开相同的 Activity 两次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29627662/