Why do we use the TaskStackBuilder when creating a notification? I do not get the logic behind it.
Can someone please explain.
public v
The other answers explained it nicely: you use a pending intent to send a user into a detail activity, then you want them to use the back button to go back to the main activity. An alternative way to set this is
Intent detailIntentForToday = new Intent(context, DetailActivity.class); TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(context); taskStackBuilder.addNextIntentWithParentStack(detailIntentForToday); PendingIntent resultPendingIntent = taskStackBuilder .getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); resultPendingIntent.send();
For this, you also need to set
android:parentActivityName=".MainActivity"
for the DetailActivity in AndroidManifest.xml.