我正在尝试为使用此代码按下通知的 Activity 重新创建返回堆栈:
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());
但它不起作用。当我按下通知时,第二个 Activity 打开但按下后退按钮, Activity 完成,而我想返回到第一个 Activity 。
在 AndroidManifest 中设置 parentActivityName 不起作用。
怎么了?
谢谢
最佳答案
尝试改变
PendingIntent.FLAG_UPDATE_CURRENT
到
PendingIntent.FLAG_CANCEL_CURRENT
关于android - PendingIntent 中的 TaskStackBuilder 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31491425/