I am trying to open an Activity when the notification is clicked and below is my code.
Intent intent = new Intent(this.getApplicationContext(),
I had the same problem in my app
This link helped me: https://developer.android.com/training/notify-user/navigation
What you need to do is define parent activity for your desired activity in Manifest:
And then use TaskStackBuilder in onMessageReceived method to create pending intent
// Create an Intent for the activity you want to start
Intent resultIntent = new Intent(this, ResultActivity.class);
// Create the TaskStackBuilder and add the intent, which inflates the back stack
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
stackBuilder.addNextIntentWithParentStack(resultIntent);
// Get the PendingIntent containing the entire back stack
PendingIntent resultPendingIntent =
stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
// then use this pending intent to build your notification