I need flow like that: When the notification appears and user clicks it, activityB should start, than if user clicks the back button it should go the activityA, my problem is that, when user clicks the notification and activityB is being lanched, stack is empty and if user clicks the back button application behavior is like pressing the home button and after I click launcher icon, it starts the launcher activity, flow is like first time launch.
Also saw google's official documentation how to use notifications correctly with preserving activities for better navigation experience, but did not help.
this is the code with displays notification
private fun sendNotification() {
val mBuilder = NotificationCompat.Builder(this)
.setContentTitle(name)
.setContentText(messageBody)
val resultIntent = Intent(this, activityB::class.java)
val stackBuilder = TaskStackBuilder.create(this)
stackBuilder.addParentStack(activityA::class.java)
stackBuilder.addNextIntent(resultIntent)
val resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT)
mBuilder.setContentIntent(resultPendingIntent)
mNotificationManager.notify(mId, mBuilder.build())
}
And here is manifest file
<activity
android:name=".activityB"
android:parentActivityName="activityA" />
<activity android:name="activityA"/>
I don't understand, what I'm missing