I’m trying to launch an activity from a notification like the Android docs explain, but when I open the notification and then press the back button, the HomeActivity (parent) doesn’t open, instead the application closes. What am I doing wrong?
Intent resultIntent = new Intent(context, MatchActivity.class);;
resultIntent.setFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
// Adds the back stack for the Intent (but not the Intent itself)
stackBuilder.addParentStack(MainActivity.class);
stackBuilder.addNextIntent(resultIntent);
You need to add the parent stack for the activity you’re launching, not the parent of it.
Replace:
with:
This assumes that you’ve defined the parent in your Manifest (API 16+):
If you’re developing for under API 16, then you have to define the parent as: