PendingIntent中的TaskStackBuilder无法正常工作

Mat*_*ska 4 android android-notifications android-activity back-stack

我正在尝试使用此代码为按下的通知重新创建一个后台堆栈:

Intent firstIntent = new Intent(this, First.class);  
Intent secondIntent = new Intent(this, Second.class);    
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);

 stackBuilder.addNextIntent(firstIntent);
 stackBuilder.addNextIntent(secondIntent);
 PendingIntent pendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); 
 Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

 NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
                                    .setSmallIcon(R.mipmap.ic_launcher)
                                    .setContentTitle(fromName)
                                    .setContentText(message)
                                    .setAutoCancel(true)
                                    .setSound(defaultSoundUri)
                                    .setContentIntent(pendingIntent);

  NotificationManager notificationManager =
                                    (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

  notificationManager.notify(0 ,notificationBuilder.build());
Run Code Online (Sandbox Code Playgroud)

但它不起作用.当我按下通知时,第二个活动被打开但按下后退按钮,活动结束,而我想回到第一个活动.

在AndroidManifest中设置parentActivityName不起作用.

怎么了?

谢谢

Gan*_*han 9

尝试改变

PendingIntent.FLAG_UPDATE_CURRENT
Run Code Online (Sandbox Code Playgroud)

PendingIntent.FLAG_CANCEL_CURRENT
Run Code Online (Sandbox Code Playgroud)