How to use Android Back Stack Navigate

android backstack

Navigate Android

Sample Scenario

You have sent a product notification to the user. When the user clicks notification A, they are directed directly to the Product Details page. When the user is finished pressing back on the page and you want to redirect the user to the home page of the application. If you are not making any additional improvement, pressing back for this scenario will close the application. Because there’s no screen to go back to. The details page has been opened directly.

Solution

First, we have to do manifest.specify parentActivityName where we define DetailActivity in the XML file. In other words, if you press the backspace key, we write this activity to the parentActivityName field, whichever activity we want to open.

Then we edit the code that we prepared for the notification demonstration as follows.

The Mainactivity page will now open when the user presses back on the DetailsActivity page that is opened with notification.