1
我正在使用firebase發送通知。當用戶點擊通知時,它將打開ResultActivity。當應用處於前臺時它工作正常。但是,當應用程序處於後臺時,它會打開HomeActivity(這是應用程序的開端活動)而不是ResultActivity。我不明白這是什麼問題?爲什麼PendingIntent會打開應用程序的啓動器活動而不是特定的活動?
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());
}
}
這個確切的問題,昨天最後問,做一些搜索你問了一個新問題之前 –
http://stackoverflow.com/questions/40718155/open-specific-activity-when-notification-clicked-in-fcm –
看一看[這裏](http://stackoverflow.com/questions/37407366/firebase-fcm-notifications-click-action-payload)。它可能會幫助你。 –