I'm able to send push notifications from console.firebase.google however, when I click on the notification that has been sent I want to be redirected to Main2Activity instead of MainActivity, I am able to achieve this when the app is in the foreground but not in the background, appreciate any help.
public class MyFirebaseMessagingService extends FirebaseMessagingService {
private static final String TAG = "FCM Service";
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Intent detailIntentForToday = new Intent(this, Main2Activity.class);
TaskStackBuilder taskStackBuilder =
TaskStackBuilder.create(getApplicationContext());
taskStackBuilder.addNextIntentWithParentStack(detailIntentForToday);
PendingIntent resultPendingIntent = taskStackBuilder
.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
Notification notification = new Notification.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle(getString(R.string.app_name))
.setAutoCancel(true)
.setPriority(Notification.PRIORITY_MAX)
.setDefaults(Notification.DEFAULT_VIBRATE)
.setContentIntent(resultPendingIntent)
.setContentText("Text")
.build();
NotificationManager notificationManager = (NotificationManager)
getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, notification);
}
}