Following snippet work for me, It will display Notification panel with required message and on Tap it launch simply Splash Screen. Now Splash screen is the screen which actually not display but guide application to display Front Activity.
private void showNotification(Context context, String message, int userId) {
// Here it play tricky part. Since Splash is the Activity which never show. It just guide which Activity should show next.
Intent intent = intent = new Intent(context, Splash.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent contentIntent = PendingIntent.getActivity(context, userId, intent , 0);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context).setSmallIcon(R.drawable.ic_launcher).setContentTitle("Alarm").setContentText(message);
mBuilder.setContentIntent(contentIntent);
mBuilder.setDefaults(Notification.DEFAULT_SOUND);
mBuilder.setAutoCancel(true);
NotificationManager mNotificationManager =
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(userId, mBuilder.build());
}
And from Splash Screen before to launch required front activity, simply call finishAffinity()
, it will clear all back stack Activity.