我正在尝试为活动重新创建一个返回堆栈在通知按下这个代码:
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());
但它不起作用。当我按下通知时,第二个活动被打开,但按下后退按钮,活动完成,而我想回到第一个活动。
在AndroidManifest中设置parentacvityname不起作用
怎么了?
谢谢
尝试更改
PendingIntent.FLAG_UPDATE_CURRENT
PendingIntent.FLAG_CANCEL_CURRENT