Skip to content Skip to sidebar Skip to footer

Pending Intent Opens Wrong Activity

I am using the FirebaseMessagingService for getting notifications and opening the app upon clickng the notification. But everytime i click the notification the app opens the MainAc

Solution 1:

Create an Intent that starts the Activity.

Set the Activity to start in a new, empty task by calling setFlags() with the flags FLAG_ACTIVITY_NEW_TASK and FLAG_ACTIVITY_CLEAR_TASK.

Create a PendingIntent by calling getActivity().

Like,

IntentnotifyIntent=newIntent(this, ResultActivity.class);
    // Set the Activity to start in a new, empty task
    notifyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | 
Intent.FLAG_ACTIVITY_CLEAR_TASK);
    // Create the PendingIntentPendingIntentnotifyPendingIntent= PendingIntent.getActivity(this, 0, 
notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT);

Then you can pass the PendingIntent to the notification as usual:

NotificationCompat.Builder mNotificationBuilder= new NotificationCompat.Builder(this, "CHANNEL_ID");
builder.setContentIntent(notifyPendingIntent);
...
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
notificationManager.notify(0, mNotificationBuilder.build());

Solution 2:

Apparently there is no way to trigger the onMessageReceived by using the FCM console only. It will only be triggered if i use other ways to send data messages.

Post a Comment for "Pending Intent Opens Wrong Activity"