我有一个Firebase通知,可以完美地发送到我的设备。出于某种原因,当我点击通知时,它会启动另一个Activity而不是我在我的方法onMessage中声明的Activity。我检查了所有可能的原因,但找不到问题。 当我点击通知时,我想将消息发送到另一个活动。
这是我的代码:
public class FireMsgService extends FirebaseMessagingService {
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
Log.d("Msg", "Message received ["+remoteMessage.getData().toString()+"]");
String notificationMessage = remoteMessage.getNotification().getBody();
String notificationTitle = "LendingSquare Alert!";
int notificationIndex = 1410;
String CHANNEL_ID = "my_channel_01";
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this, CHANNEL_ID)
.setSmallIcon(R.drawable.logo)
.setContentTitle(notificationTitle)
.setContentText(notificationMessage);
// Creates an explicit intent for an Activity in your app
Intent resultIntent = new Intent(this, NotificationActivity.class);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
// Adds the back stack for the Intent (but not the Intent itself)
stackBuilder.addParentStack(NotificationActivity.class);
// Adds the Intent that starts the Activity to the top of the stack
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent =
stackBuilder.getPendingIntent(
0,
PendingIntent.FLAG_UPDATE_CURRENT
);
mBuilder.setContentIntent(resultPendingIntent);
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(notificationIndex, mBuilder.build());
}
}