【发布时间】:2020-04-13 13:52:47
【问题描述】:
我正在使用 firebase 发送通知。当用户单击通知时,它将打开 ResultActivity。当应用程序处于前台时,它工作正常。但是当应用程序在后台时,它会打开 HomeActivity(这是应用程序的启动器活动)而不是 ResultActivity。我不明白这是什么问题?
public class MyFirebaseMessagingService extends FirebaseMessagingService {
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this);
notificationBuilder.setContentTitle(getResources().getString(R.string.app_name));
notificationBuilder.setContentText(remoteMessage.getNotification().getBody());
notificationBuilder.setAutoCancel(true);
notificationBuilder.setSmallIcon(R.mipmap.ic_launcher);
Intent intent = new Intent(getApplicationContext(), ResultActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent, PendingIntent.FLAG_ONE_SHOT);
notificationBuilder.setContentIntent(pendingIntent);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, notificationBuilder.build());
}
}
【问题讨论】:
-
看看here。它可能会对你有所帮助。
标签: android android-pendingintent firebase-notifications