Building back stack correctly when coming from a notification on Android
After I added some notifications to my app I noticed that they weren’t behaving the way I wanted them to behave. When I clicked on a notification I landed on one of my internal screens. When I clicked back I was expecting to go to the main screen but instead it went back to the phone home.
After reading a little I discovered that there is a difference between navigating back and navigating up (Read the related links to learn more), and that I needed to properly set the up navigation before I could fix this.
To set the up navigation correctly you need to specify a parent for each of your activities in your manifest:
1
2
3
4
5
6
7
<activity android:name="Internal" android:label="@string/app_name"
android:screenOrientation="portrait"
android:parentActivityName=".MainActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>