I am trying to recreate a back stack for the Activity on notification pressed with this code:
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());
but it doesn't work. When I press the notification the Second activity is opened but pressing the back button, the activity is finished while I want to go back to First activity.
Setting parentActivityName in the AndroidManifest doesn't work.
What is wrong?
Thanks
Try changing
PendingIntent.FLAG_UPDATE_CURRENT
to
PendingIntent.FLAG_CANCEL_CURRENT
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With