1

In the android, FCM notification comes and app is in the background state and when tapped, it redirects to Default Activity (LoginActivity) but I want to navigate to specified activity (HomeActivity).

    NotificationCompat.Builder notification = new NotificationCompat.Builder(this, "CHANNEL_1");
    notification/*.setSound(soundUri)*/
            .setSmallIcon(R.drawable.ic_photo_camera_black_24dp)
            .setColor(getResources().getColor(R.color.colorAccent))
            .setAutoCancel(true)
            .setContentTitle(title)
            .setContentText(message);

    Intent intent = new Intent(this, HomeActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent,
            0);

    notification.setContentIntent(pendingIntent);
    NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(1, notification.build());
  • Please post some code to show what you have done – AbhayBohra Nov 26 '19 at 06:58
  • This code is perfect some other coding mistake you have. – Thoriya Prahalad Nov 26 '19 at 07:16
  • when i send "notification json", it opens default activity when app is in the background "notification": { "body": "Hello data", "title": "This is test title data.", "message": "This is test message. data" } when i send "data json", it opens particular activity when app is in the background "data": { "body": "Hello data", "title": "This is test title data.", "message": "This is test message. data" } – Jeevan Jadhav Nov 26 '19 at 07:33
  • Where this code is written? – Zach Bublil Nov 26 '19 at 07:41

2 Answers2

0

you will need to pass an activity parameter from the api/json part. from your app side you will check for the activity nave and than open accordingly

see this solution https://stackoverflow.com/a/39665485/6442746 for more insights.

takiuddin93
  • 41
  • 2
  • 11
0

You should send a format is Data Message to handle notification in onMessageReceived when the app is background or foreground enter image description here

When received data in onMessageReceived(), you can show notification and direct to your activity.

Cuong Nguyen
  • 970
  • 6
  • 17