I have tried one sample.Please go through with this link
https://github.com/rajajawahar/NotificationBackStack
Activity you want to launch..
Intent launchIntent = new Intent(context, SecondActivity.class).putExtra("Id", id);
Parent Activity, if back pressed
Intent parentIntent = new Intent(context, FirstActivity.class);
Add Both the activity in the taskbuilder
TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); 
    PendingIntent resultPendingIntent = stackBuilder.addNextIntentWithParentStack(parentIntent).addNextIntent(launchIntent).getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder notificationCompatBuilder =
                new NotificationCompat.Builder(context);
        NotificationManager mNotificationManager =
                (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        mNotificationManager.notify(id, notificationCompatBuilder.build());
        NotificationManager mNotifyMgr =
                (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        notificationCompatBuilder.setAutoCancel(true).
                setContentTitle("First Notification").
                setContentText("Sample Text").
                setSmallIcon(R.mipmap.ic_launcher).
                setContentIntent(resultPendingIntent);
        mNotifyMgr.notify(id, notificationCompatBuilder.build());